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
Answer from Chetan Ameta on Stack Overflowphp - Length array in array - Stack Overflow
How to declare the length/size of an array in php, so users can input any size - Stack Overflow
I found a website completely about finding the length of an array in PHP.
Large Loops
What is the primary function to get the PHP array length?
How do I properly use the PHP array length in a for loop?
";}
What is the easiest way to find the length of an array in PHP?
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
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);
}
}
In PHP you define/declare an array by just
$oldSchool = array();
$newSchool = []; // use this one!
You can add new elements to it by simply using [] next to the array as:
$array[] = 'new element';
count($array); // returns the lenght of the array
You can easily iterate an array using a foreach loop:
foreach($array as $key => $value) {
echo sprintf('key: %s, value: %s',$key, $value) . PHP_EOL;
}
There are plenty of in-build php functions to play with arrays https://www.php.net/manual/en/ref.array.php
PHP doesn't have a concept of arrays. It has ordered maps which it calls arrays. They have no finite size. You can't have a fixed size array unless you use the SplFixedArray class
To create PHP's "array" you can use the following syntax.
$myArray = [];
To add elements you use keys. This will map one value to another.
$myArray['myKey'] = 'My string';
You can also use numerical keys or append a new value to the map.
$myArray[42] = 'My string of 42';
$myArray[] = 'Appended value'; // the key will be generated by PHP and will be the next available numerical value