Styleminds
asked on
combine arrays php
Hello i have three arrays
$name(..here goes the details..);
$numbers(..here goes the details..);
$website(..here goes the details..);
I need to combine these arrays and make them share same key for getting result like this
foreach ($array as $c){
echo $x['name'];
echo $x['numbers'];
echo $x['website']';
}
$name(..here goes the details..);
$numbers(..here goes the details..);
$website(..here goes the details..);
I need to combine these arrays and make them share same key for getting result like this
foreach ($array as $c){
echo $x['name'];
echo $x['numbers'];
echo $x['website']';
}
Previous code doesn't work. Snippet below is better but it doesn't create an associative array. See if it works for you, please.
<?php
$name=array("name1", "name2", "name3");
$numbers= array("1","2","3");
$website=array("www.sito1.com","www.sito2.com","www.sito3.com");
$array = array();
for ($i=0;$i<count($name);$i++){
$array['name'][$i] = $name[$i];
$array['numbers'][$i] = $numbers[$i];
$array['website'][$i] = $website[$i];
}
foreach ($array as $x){
echo $x[0]."<br>";
echo $x[1]."<br>";
echo $x[2]."<br>";
}
?>
ASKER
but that is not what i need what i need to get result
name1
1
www.sito1.com
name2
2
www.sito2.com
3
name3
www.sito3.com
I need the result to be same as i am fetching a database and getting rows related a certain table
name1
1
www.sito1.com
name2
2
www.sito2.com
3
name3
www.sito3.com
I need the result to be same as i am fetching a database and getting rows related a certain table
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$array = array();
for ($i=0;$i<count($name);$i++
$array['name'] = $name[$i];
$array['numbers'] = $numbers[$i];
$array['website'] = $website[$i];
}
Hope this helps