Change language

How to check if an array is multidimensional or not in PHP?

Syntax:
rsort ($array) 
Parameters:Function rsort() takes one parameter.
  • $array:is an object, which you want to pass to the function.
Example 1:The PHP program to validate the array is multidimensional or does not use the rsortfunction. $myarray = array ( // Default key for each will // start at 0 array ( " Geeks " , "For" , "Geeks " ), array ( "Hello" , "World" ) );  
// Function for checking the array
// multidimensional or not function is_multi_array ( $arr ) { rsort ( $arr ); return isset ( $arr [0]) & amp; & amp; is_array ( $arr [0]); }  
// Show result var_dump (is_multi_array ( $myarray )); ?>
Exit:
bool (true ) 
Example 2Another PHP program for checking an array is multidimensional or does not use the countfunction.
// Declare the array $engineer = array (1 = > ’a’ , 2 = > ’ b’ , 3 = > array ( "Learn" , "Contribute" , " Explore " )); $gfg = array (1 = > ’a’ , 2 = > ’b’ );  
// Function for checking the array
// multidimensional or not function is_multi ( $engineer ) {   $rv = array_filter ( $engineer , ’is_array’ ); if ( count ( $rv ) > 0) return true; return false; }  
// Show result var_dump (is_multi ( $engineer )); var_dump (is_multi ( $gfg ) ); ?>
Exit:
bool (true ) bool (false) 
Note:Try to avoid using count and count_recursive to check if an array is multidimensional or not, because you may not know if an array can survive an array, containing a subarray, or not, which is empty.

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method