if I have an array like this:
$array = array(
1,
2,
3,
["thing1", "thing2", "thing3"]
);
how do I check what the lenght is of the array in the array ( ["thing1", "thing2", "thing3"] )?
if I have an array like this:
$array = array(
1,
2,
3,
["thing1", "thing2", "thing3"]
);
how do I check what the lenght is of the array in the array ( ["thing1", "thing2", "thing3"] )?
You can use Array Count function count or sizeof function.
try below code:
$array = array(
1,
2,
3,
["thing1", "thing2", "thing3"]
);
echo count($array[3]); //out put 3
echo sizeof($array[3]); //out put 3
count is probably preferable over sizeof if you do go with this method, sizeof is just an alias of count, and can cause confusion for some programmers since it doesn't do what many expect it to.You can use the count function:
echo count($array[3]);
However if the array you want to get the length is not always in this same position you could do something like this:
foreach ($array as $element) {
if (is_array($element) {
echo count($element);
}
}