array_values


php128 apg

RETURNS all the values of a given ARRAY.





This function returns all the values from the $array and indexes the ARRAY numerically.



<?php

arr array_values 
arr $array )


where,

$array The working array

?>

 $array 


The working array.



  1 EXERCISE   

<?php

$arr01 
= [ "K" => 2"L" => 8
                
"M" => 18"N" => 32
                
"O" => 32"P" => 18
                
"Q" => ];

$vals01 array_values($arr01);

echo 
'The given ARRAY:<br><pre>';

print_r($arr01);

echo 
'</pre><br><br>After applying array_values:<br><pre>';

print_r($vals01);

echo 
'</pre>';


?>

 RESULT   

The given ARRAY:
Array
(
[K] => 2
[L] => 8
[M] => 18
[N] => 32
[O] => 32
[P] => 18
[Q] => 8
)



After applying array_values:
Array
(
[0] => 2
[1] => 8
[2] => 18
[3] => 32
[4] => 32
[5] => 18
[6] => 8
)


  2 EXERCISE   

<?php

$arr02 
= array("RGB" => array("RED""GREEN""BLUE"), 
                    
"HSB" => array("HUE""SATURATION""BLACK") );

$vals02 array_values($arr02);

echo 
'The given ARRAY:<br><pre>';

var_dump($arr02);

echo 
'</pre><br><br>After applying array_values:<br><pre>';

var_dump($vals02);

echo 
'</pre>';


?>

 RESULT   

The given ARRAY:
array(2) {
["RGB"]=>
array(3) {
[0]=>
string(3) "RED"
[1]=>
string(5) "GREEN"
[2]=>
string(4) "BLUE"
}
["HSB"]=>
array(3) {
[0]=>
string(3) "HUE"
[1]=>
string(10) "SATURATION"
[2]=>
string(5) "BLACK"
}
}



After applying array_values:
array(2) {
[0]=>
array(3) {
[0]=>
string(3) "RED"
[1]=>
string(5) "GREEN"
[2]=>
string(4) "BLUE"
}
[1]=>
array(3) {
[0]=>
string(3) "HUE"
[1]=>
string(10) "SATURATION"
[2]=>
string(5) "BLACK"
}
}