0

I have this array:

$rows = array_map(function($item) {
return (object) ['c' => [
    (object) ['v' => $item->job_type, 'f' => null],
    (object) ['v' => intval($item->count), 'f' => null]
]];
}, array_values($data));

echo json_encode($data);

The output is like this:

{"1":{"job_id":"1","count":"8","job_type":"0"},"3":{"job_id":"3","count":"7","job_type":"1"}}

I want to change the value of job type from "0" to "job" and "1" to Internship.

How can i do that?

joun
  • 656
  • 1
  • 8
  • 25
  • this may help - https://stackoverflow.com/questions/240660/in-php-how-do-you-change-the-key-of-an-array-element – genesst Sep 19 '17 at 01:58
  • Possible duplicate of [In PHP, how do you change the key of an array element?](https://stackoverflow.com/questions/240660/in-php-how-do-you-change-the-key-of-an-array-element) – genesst Sep 19 '17 at 01:59
  • have another array (or class) that defines that strings.`$jobTypes = [0=>'job',..]`. Then have smth like `'v' => $jobTypes[$item->job_type],..` – Jeff Sep 19 '17 at 02:00
  • I am sorry, but still confusing. I cannot change the value of the array. – joun Sep 19 '17 at 06:32
  • can someone give help? – joun Sep 19 '17 at 10:15

0 Answers0