6

I am unable get interview_docs data from php array in angularjs. i tried many json encode options but it didnt woked out.How to get interview_docs data in js This is my array :

Array(
[id] => 1
[tag] => 2
[title] => Test
[job_submission_id] => 0
[job_id] => 14
[candidate_id] => 55
[mail_to] => test@gmail.com
[cc_to] => test@gmail.com
[interviewer] => test@gmail.com
[interview_type] => 1
[interview_date] => 2017-10-04
[from_time] => 00:00:00
[to_time] => 01:00:00
[to_date] => 
[location] => 
[time_zone] => Asia/Kolkata
[status] => 1
[comments] => dwedfwef
[created_by] => 1
[modified_by] => 1
[created_at] => 2017-10-03 12:21:13
[updated_at] => 2017-10-03 12:21:13
[job_title] => Test
[candidate_name] => New t

[candidates] => Array
    (
        [id] => 55
        [first_name] => New
        [last_name] => t
    )

[jobs] => Array
    (
        [id] => 14
        [code] => 10
        [title] => Test
    )

[interview_docs] => Array
    (
        [0] => Array
            (
                [id] => 1
                [interview_id] => 1
                [unique_name] => 2017_10_roa2XKlIDc9gmzmO7TK37rsfuX3YRigqUxbvIYWe.txt
                [name] => first.png
            )

        [1] => Array
            (
                [id] => 2
                [interview_id] => 1
                [unique_name] => 2017_10_6RaAm3MU5ZZ1x4l3q8VLYNhUkgvS3v2ljNZVizm1.png
                [name] => Screenshot (15).png
            )

    )

)

when i did this : var data = <?php echo json_encode($array); ?>; console.log(data); i am getting this

interview_docs:Array(0)
length:0
 __proto__:Array(0)

I am unable get interview_docs data from php array in angularjs. i tried many json encode options but it didnt woked out.How to get interview_docs data

siva sandeep
  • 557
  • 1
  • 5
  • 17

2 Answers2

0

if you want to encode your data then your array should look like this one...

Also I commented a line if you want to access to any element of your array.

I tested it minutes ago, now you only need to connect it using an $http service from angularjs to connect this Backend.

I hope it helps :)

<?php

error_reporting(E_ALL);
ini_set('display_errors',1);

$array=array(
    "id"=>1,
    "tag"=>2,
    "title"=>"Test",
    "job_submission_id"=>0,
    "job_id"=>14,
    "candidate_id"=>55,
    "mail_to"=>"test@gmail.com",
    "cc_to"=>"test@gmail.com",
    "interviewer"=>"test@gmail.com",
    "interview_type"=>1,
    "interview_date"=>"2017-10-04",
    "from_time"=>"00:00:00",
    "to_time"=>"01:00:00",
    "to_date"=>"",
    "location"=>"",
    "time_zone"=>"Asia/Kolkata",
    "status"=>1,
    "comments"=>"dwedfwef",
    "created_by"=>1,
    "modified_by"=>1,
    "created_at"=>"2017-10-03 12:21:13",
    "updated_at"=>"2017-10-03 12:21:13",
    "job_title"=>"Test",
    "candidate_name"=>"New t",
    "candidates"=>array(
        "id"=>55,
        "first_name"=>"New",
        "last_name"=>"t"
    ),
    "jobs"=>array(
        "id"=>14,
        "code"=>10,
        "title"=>"Test"
    ),
    "interview_docs"=>array(
        "0"=>array(
                "id"=>1,
                "interview_id"=>1,
                "unique_name"=>"2017_10_roa2XKlIDc9gmzmO7TK37rsfuX3YRigqUxbvIYWe.txt",
                "name"=>"first.png"
        ),
        "1"=>array(
                "id"=>2,
                "interview_id"=>1,
                "unique_name"=>"2017_10_6RaAm3MU5ZZ1x4l3q8VLYNhUkgvS3v2ljNZVizm1.png",
                "name"=>"Screenshot (15).png"
        )
    )
);
// echo "unique_name from interview_docs is: <b>".$array["interview_docs"][0]["unique_name"]."</b><br><br>"; // You can access to data like this :)
echo json_encode($array);
?>
  • 2
    Question is over a year old, the question does not provide enough information to be answered, and the user has never accepted an answer to a question they've asked. All good reasons not to bother with this. – miken32 Dec 27 '18 at 21:17
  • No worries; the real mystery is who thought this question was worth 7 upvotes. – miken32 Dec 27 '18 at 21:34
-1

First you have to die() it encoding to JSON and then you can console.log() it at .js:

die(json_encode($array));
Felipe G.
  • 154
  • 1
  • 9