0

I have a multidimensional array with original value and changed value like this:

$arr = [
    'first_name' => [
        'original' => 'Rahul',
        'changes' => 'Manan'
    ],
    'last_name' => [
        'original' => 'Shah',
        'changes' => 'Patel'
    ],
    'email_address' => [
        'original' => 'rahul@yahoo.com',
        'changes' => 'manan@gmail.com'
    ]
];

Now I want to concatenate a string with the main array key name along with original & changes value like this:

$str = 'first_name Rahul => Manan, last_name Shah => Patel, email_address rahul@yahoo.com => manan@gmail.com';

Any idea how to do this thing with loop?

Mr.Happy
  • 517
  • 1
  • 9
  • 25
  • 3
    This looks like a pretty basic loop. Did you make any attempt? – Jeto Nov 09 '19 at 10:49
  • Possible duplicate of [Sort array of objects by string property value](https://stackoverflow.com/questions/1129216/sort-array-of-objects-by-string-property-value) – SuperStar518 Nov 09 '19 at 13:49

1 Answers1

0

You could try using a foreach and string concat

$str ='';
foreach($arr as $key=>$value){

  $str .= ($str == '' ? 
        $key .' ' . $value['original']  .' => ' . $value['changes'] 
      : ', '.  $key .' ' . $value['original']  .' => ' . $value['changes']  );

}
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107