Example: When adding square brackets to $main_array, I get 3 dots inside array but when I remove those brackets, it works good.
<?php
$user = array('a','b','c');
$cars=array("Volvo","BMW","Toyota");
$roll = array(1,2,3);
$length = count($user);
$main_array = array();
foreach($user as $name){
$list = array();
for($i=0;$i<$length;$i++){
$list[] = array(
'label' => $cars[$i],
'roll' => $roll[$i]
);
}
$main_array[] = array(
'name'=> $name,
'list'=> $list
);
}
var_dump($main_array);
?>
Added.... So here is what I am trying to do. Trying to pull feed from twitter api 1.1
$status = array();
$tweetfeed = array();
foreach($users as $user){
$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$user."&count=".$notweets);
$t=0;
foreach($tweets as $key) {
$status[$t]['text'] = $key ->text;
$status[$t]['stamp'] = twitter_time($key -> created_at);
++$t;
}
$tweetfeed = array (
'status' => $status
);
var_dump($tweetfeed);
}
var_dump($tweetfeed);
..End
foreach($user)
Main_parent {
Child-1{
'key': value
'key': value
}
Child-2{
'key': value
'key': value
}
Child-3{
'key': value
'key': value
}
}
var_dump(Main_parent);
}
var_dump(Main_parent);
Calling Main_parent with in foreach loop is working fine but when called outside foreach loop is only showing child-3.