Array location in table

I need help, I have a problem with Array results .

The code I'm using is:

   $presents = json_decode(fBGetDataStore('presents'), true); 

and print the result:

       <?= print_r($presents) ?>

shows this result :

  Array ( [0] => Array ( [sender] => 100009016810227 [itemCode] => 0f8g [itemContext] => normal [extraData] => ) 
          [1] => Array ( [sender] => 100009016810227 [itemCode] => 0fcm [itemContext] => normal [extraData] => )

But I want the result:

[1] Sender ID: 100009016810227 and Item Code is 0f8g
[2] Sender ID: 100009016810227 and Item Code is 0fcm
+4
source share
2 answers

I did as you said @FatAdama

Coding:

foreach ($presents as $key=>$value) { echo 'Sender ID: '.$value['sender'].' and Item Code is '.$value['itemCode'].'<br>'; }

and I get the results of my desire ^ _ ^:

Sender ID: 100009016810227 and Item Code is 0f8g Sender ID: 100009016810227 and Item Code is 0fcm

Thank you for your help.

+2
source

You can simply iterate over with foreach and build the desired output into an output array, like this

foreach ($presents as $key=>$value) {
     $newKey = $key + 1;
     $output[$newKey] = "Sender ID: {$value['sender']} and Item Code is {$value['itemCode']}";
}

Where $outputshould the array be formatted according to your specifications.

+2
source

All Articles