2

How to produce result like

"alpa":[{"a":"a"},{"b":"b"},{"c":"c"}]

so I can easily get them in JS.

My code currently is like this:

$arr = array();
$arr["a"] = $a;
$arr["b"] = $b;
$arr["c"] = $c;

echo json_encode($arr);

output

{"a":"a"},{"b":"b"},{"c":"c"}
1
  • change $arr to $arr['alpa'] Commented Jan 5, 2015 at 4:49

2 Answers 2

1
array(
    'alpa' => array(
        'a' => 'a',
        'b' => 'b',
        'c' => 'c',
    )
);
Sign up to request clarification or add additional context in comments.

Comments

1

Try this

$arr = array();
$arr['alpa']["a"] = $a;
$arr['alpa']["b"] = $b;
$arr['alpa']["c"] = $c;
echo json_encode($arr);

Comments

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.