I’m teaching myself PHP and I have the following question about arrays:
I have:
$names = array('John', 'Alice', 'Tom');
$cities = array('London', 'NY', 'Boston');
$years = array('1999', '2010', '2012');
$colors = array('red', 'blue', 'green');
I want to have a new array with these elements (three subarrays):
John London 1999 red
Alice NY 2010 blue
Tom Boston 2012 green
I’m doing
$newArray = array($names,$cities, $years,$colors);
But this shows all the names, cities and so all together 🙁 Please show me how to achieve this.
Thanks a lot!
If You want the three list to be arrays with each value an element in a sub array, do this:
This gives an output of:
If you want the result to be an array of strings use Mihai’s answer.