-1

I have a Request in laravel where I pass a json object. The json is the following: { "firstname": "michael" }.

I am writing a dynamic search function and I want to store the data as 2 different values the "firstname" and the "michael". How can I do that in php ?

Tpojka
  • 6,996
  • 2
  • 29
  • 39
Joe Mash
  • 39
  • 1
  • 6
  • http://php.net/manual/en/function.json-decode.php would be a good start –  Jan 16 '19 at 00:34

1 Answers1

0
<?php

$array = json_decode('{"firstname":"michael"}', TRUE);

foreach ($array as $first => $second){
    echo "first: {$first}\nsecond: {$second}";
}

Return:

first: firstname
second: michael
Se Kh
  • 37
  • 2
  • the provblem is that i dont know if the my GUI gives me firstname or lastname ... i am writing a dynamic search function so i wanna get every time the key value and the value in 2 parts to pass them to my search function ... – Joe Mash Jan 16 '19 at 00:43