Ccna final exam - java, php, javascript, ios, cshap all in one. This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
Friday, January 13, 2012
How do I build a complex array in PHP?
How can I build an array like this in PHP?
It should have unique keys each of whose corresponding values are arrays, and those arrays have multiple elements for each key.
$main = array();
ReplyDeletefor ($i=0; $i<10; $i++) {
// $i makes numeric keys
$main[$i] = array();
// Or instead, you could make a truly unique key name for each:
$main[uniqid()] = array(...somevalues...);
}
Creates something like:
Array
(
[4f105f361cdd1] => Array
(
)
[4f105f361cf24] => Array
(
)
[4f105f361cf33] => Array
(
)
[4f105f361cf3c] => Array
(
)
[4f105f361cf44] => Array
(
)
)
$arr = array(
ReplyDelete42 => array(56, 86, 97),
51 => array(64, 52)
);
var_dump($arr);
$array = array(42=>array(56,86,97),51=>array(64,52));
ReplyDelete$arraytest = array(
ReplyDelete42 => array(56, 86, 97),
51 => array(64, 52)
);
var_dump($arraytest);