This is a multidimensional PHP array.
$stdnt = array(
array("Arafat", 12210261, 2.91),
array("Rafat", 12210262, 2.92),
array("Marlin", 12210263, 2.93),
array("Aziz", 12210264, 2.94),
);
I can find out the length of the array. That means
count($stdnt); // output is 4
[
array("Arafat", 12210261, 2.91),
array("Rafat", 12210262, 2.92),
array("Marlin", 12210263, 2.93),
array("Aziz", 12210264, 2.94)
] `
But can't get the internal array length.
How can I ?
Example 3: Find Length of Multidimensional Array In the following program, we are initializing a two dimensional PHP array. Then we are using count() function to find the number of elements in the array. Pass array as first argument and COUNT_RECURSIVE as second argument.
To get the length of a 2D Array in Python: Pass the entire array to the len() function to get the number of rows. Pass the first array element to the len() function to get the number of columns. Multiply the number of rows by the number of columns to get the total.
To determine the number of elements in the array, we can divide the total size of the array by the size of the array element. You could do this with the type, like this: int a[17]; size_t n = sizeof(a) / sizeof(int);
A multidimensional array is an array containing one or more arrays. PHP supports multidimensional arrays that are two, three, four, five, or more levels deep. However, arrays more than three levels deep are hard to manage for most people.
If you are assuming the subarrays are all the same length then:
$count = count($stdnt[0]);
If you don't know the keys:
$count = count(reset($stdnt));
To get an array with a separate count of each of the subarrays:
$counts = array_map('count', $stdnt);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With