I wanted to combine three arrays inside a foreach,
$topic = explode(',',$data->topic);
$description = explode(',',$data->description);
foreach (array_combine($topic, $description) as $topic => $description)
{
echo $topic;
echo $description;
}
Which is working for two arrays, but I want for three arrays, because I want to pass $id = explode(',',$data->id);
also in the same array which is not possible using array_combine, can anyone help by passing three arrays inside same foreach?
If the ID, topic and description are all in the correct order in each comma delimited string you are supplying to the script, you could use the following to create a single array key'd by the ID:
$id = explode(',',$data->id);
$topic = explode(',',$data->topic);
$description = explode(',',$data->description);
foreach($id as $key=>$val)
{
$results[$val]['topic'] = $topic[$key];
$results[$val]['description'] = $description[$key];
}
try this:
$newArray=array_merge($topic,$description,$third_array);
foreach($newArray as $key=>$value)
{
echo "$key- $value <br/>";
}