sizeof php count(), count(), " - " . , - COUNT_RECURSIVE, 1 ( - 0), , .
PHP: ?
count() sizeof php , .
$array = array( "fruit" =>array( "apple", "bananas", "orange", ), "vegetables" =>array( "potatoes", "tomatoes", ), ); echo " = ".sizeof($array); // = 2 echo " = ".sizeof($array, 1); // = 7
( 65000 ) , sizeof() , count(), .
sizeof php , , .
$test = array( 1, 2, 3, 4 ); $sizeof_test = sizeof( $test ); for ( $it=0; $it < $sizeof_test; $it++ ) { echo $test[$it]; }
1000 , 250 .
:
$test2 = array( '', null, false, 0 ); var_dump( sizeof( $test2 ) ); // int(4) var_dump( sizeof( array_filter( $test2 ) ) ); // int(0)
, sizeof php ( count ), , , ( ) array_filter .
$test2:
$test2 = array( '',null,false,0, array() ); // int(0) $test2 = array( '',null,false,0, array( null ) ); // int(1) var_dump( sizeof( array_filter( $test2 ) ) );
array_filter , , "null" "" , sizeof php .
, array_filter?
$test2 = array('', null, false, 0, array() ); // int(5) $test2 = array('', null, false, 0, array( null ) ); // int(5) $t_rec = array('', null, false, 0, array() ); // int(5) $t_rec = array('', null, false, 0, array( null ) ); // int(6) var_dump( sizeof( $test2 ) ); var_dump( sizeof( $t_rec, 1 ) );
, - , . .
StdClass json_decode sizeof php?
$json = '{ "foo": "bar", "number": 10 , "car": "BMW" }'; $stdInstance = json_decode( $json ); var_dump( sizeof( ( array )$stdInstance ) ); // int(3) var_dump( sizeof( get_object_vars( $stdInstance ) ) ); // int(3)
Sizeof() Countable. StdClass , . , get_object_vars. (array) , .
Get_object_vars , .