在PHP中使用JSON数组

Thanks for the downvote.

I have a REST API that returns a list of tasks in JSON Format, I decode it into an array Using :

$decoded = json_decode($curl_response,true); 

and am having trouble in using that array.

EDIT : Sorry for modifying question but the curl_response is

{
    "error": true,
    "message": "Api key is misssing"
}

When I login there is an api key in JSON response, I don't know how to use further. That key is required for authentication in any further call of api.How to include that apikey in my request header for further curl calls ? Thanks.

The response is of the form (as tested using Advanced REST Client in Chrome):

{
    error: false
    tasks: [5]
        0:  {
            id: 2
            task: "v@q.com"
            status: 0
            createdAt: "2014-10-21 21:42:48"
        }-
        1:  {
            id: 3
            task: "Inter Nam"
            status: 0
            createdAt: "2014-10-21 21:42:58"
        }-
        2:  {
            id: 4
            task: "Vamos"
            status: 0
            createdAt: "2014-10-21 21:43:04"
        }-
        3:  {
            id: 5
            task: "El Mundo"
            status: 0
            createdAt: "2014-10-21 23:12:33"
        }-
        4:  {
            id: 6
            task: "El Clasico"
            status: 0
            createdAt: "2014-10-21 23:12:45"
        }-
    -
}

I tried to decode the above response in an array $decoded and then I want to display each task in a loop, get total no. of tasks..etc. --------------------------------(1) Using Count($decoded) I get 2 which is clearly wrong, also I am unable to to get the individual tasks using :

foreach($decoded as $task) {
    echo $task["task"];
}

How to implement (1) ? Thanks for your help.

There is another level above what are you trying to access. Try this:

$tasks = $decoded['tasks'];
foreach($tasks as $task) {
    echo $task["task"];
}