I would like to get the values from this array into two variables:
for each of these inner arrays. How can I do it?
Array
(
[0] => Array
(
[0] => Reuters
[1] => http://www.reuters.com
)
[1] => Array
(
[0] => CNN
[1] => http://www.cnn.com
)
)
This would give you two arrays with your titles and urls:
foreach ($array as $value)
{
$title[] = $value[0];
$url[] = $value[1];
}
Or if you want to get your values into variables:
$title1 = $array[0][0];
$title2 = $array[1][0];
$url1 = $array[1][0];
$url2 = $array[1][1];
While Anas' answer should work, I can't see the point of separating the data, because they obviously belong together (name & url is like horse and carriage, love and Marriage...)
$input = array(array('CNN','http://www.cnn.com'),array('rubbish','http://www.fox.com'));
$grouped = array();
while($pair = array_shift($input))
{
$grouped[$pair[0]] = $pair[1];
}
echo $grouped['rubbish'];//echoes http://www.fox.com
Benefits of this approach?
$title = array_keys($grouped);
$urls = array_values($grouped);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With