1

I have three JSON arrays Now I have decoded(json_decode) to convert it into PHP associative arrays in the result it's showing this result.

enter image description here

Now I want to show this three array in one table like this.

enter image description here

How can I do that please help.

Salman Iqbal
  • 442
  • 5
  • 23
  • Where is your coding attempt? – mickmackusa Nov 02 '17 at 11:58
  • Possible duplicate of [php array combine 3 arrays](https://stackoverflow.com/questions/45955796/php-array-combine-3-arrays) or maybe https://stackoverflow.com/q/43948739/2943403 or maybe https://stackoverflow.com/questions/46092795/how-to-convert-a-multidimensional-array-into-a-single-line-array-in-php – mickmackusa Nov 02 '17 at 12:00
  • Always post your code and data as text, not images. Do not post comments under the answers to say "Thanks" -- the placeholder text actually says: _Use comments to ask for more information or suggest improvements. Avoid comments lke "+1" or "thanks"._ – mickmackusa Nov 02 '17 at 12:04
  • ok I will never repeat – Salman Iqbal Nov 02 '17 at 12:14
  • Now is a good time to improve your question with an edit. Take the time to copy/paste the three arrays into your question as text. Also, post the actual code that you tried to self-solve with -- it doesn't have to be great, it just needs to exist. Finally, instead of an image of your desired output, write it out in array-form or in html form -- again, in text. Your images look small and blurry on my computer, it would improve the quality of your question to make these adjustments. Thank you in advance for taking good care of your question. – mickmackusa Nov 02 '17 at 12:18
  • Those are indexed arrays, not associative. – Tpojka Nov 02 '17 at 15:36

3 Answers3

2

This may not be the best answer, if the order of the value and their association to each other in not in the same order. But you can do it like this:

$mainarray = [];
foreach($array1 as $key => $name){
   $mainarray[$key] = [
      'name' => $name,
      'date_addded' => $arrayDate[$key],
      'status' => $arrayStatus[$key]
   ];
}

then you can use the main array in your view to generate the table list.

Mark Ryan Orosa
  • 847
  • 1
  • 6
  • 21
1

Checkout this example

    $a1=array("red","green");
    $a2=array("blue","yellow");

    print_r(array_merge($a1,$a2));

UPDATE

in case if you have more tham three or more array

$keys   = array('1','2','3');
$names  = array('Bob','Fred','Joe');
$emails = array('a@mail.com','b@mail.com','c@mail.com');
$ids    = array(A1,A2,A3);
//Create a blank array
$result = array();

foreach ($keys as $id => $key) {
    $result[$key] = array(
        'name'  => $names[$id],
        'email' => $emails[$id],
        'id'    => $ids[$id],
    );
}
TarangP
  • 2,711
  • 5
  • 20
  • 41
1
$get_id=$data->get_id;
$get_product=$data->get_product;
$get_comment=$data->get_comment;

foreach($get_id as $i => $id){
    $product = $get_product[$i];
    $comment = $get_comment[$i];
    echo "$id , $product, $comment<br/>";
}

This solution assumes the $get_id, $get_product, and $get_comment arrays are all indexed the same way.

Salman Iqbal
  • 442
  • 5
  • 23