1

I find it difficult to create JSON data. I was wanna make out JSON like the picture below

enter image description here

but I'm having trouble. I am only able to make like the picture below

enter image description here

The following code I created. please help me, I am really very confused

foreach ($q->result() as $row){
  $djson[] = array(
    'id' => $row->id_custome,
    'name' => $row->nama_custome
    );
}
return $djson;
0

1 Answer 1

3

You should use the key/index

        foreach ($q->result() as $key=>$row){
          $djson[ ( $key + 1 ) ] = array(
              'id' => $row->id_custome,
              'name' => $row->nama_custome
          );
        }
        return $djson;

Note: $key + 1 because you want to start the json from 1.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much, really i'm so happy :) now i can, thanks again
Great! Im happy to help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.