0

I have below array structure how to parse this array and to display all values of [hits][hits] in codeigniter. Can anyone help me with the code?

  Array
(
    [took] => 2
    [timed_out] => 
    [_shards] => Array
        (
            [total] => 5
            [successful] => 5
            [skipped] => 0
            [failed] => 0
        )

    [hits] => Array
        (
            [total] => 211
            [max_score] => 1
            [hits] => Array
                (
                    [0] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => AULz9GEBLWX90hClBAhn
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 5
                                    [First name] => c
                                    [Last name] => d
                                    [Email] => [email protected]
                                    [Phone] => 12
                                    [Address] => n
                                    [Password] => HARI
                                    [Status] => false
                                )

                        )

                    [1] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => eM1j6mEB19ahvbtRhU6F
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                    [2] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => ec1j6mEB19ahvbtRhk5G
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                    [3] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => es1j6mEB19ahvbtRh04U
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                    [4] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => fM1j6mEB19ahvbtRiE6M
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                    [5] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => ds1j6mEB19ahvbtRg07Y
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                    [6] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => d81j6mEB19ahvbtRhE6q
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                    [7] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => hs1j6mEB19ahvbtRok5L
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                    [8] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => iM1j6mEB19ahvbtRpU41
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                    [9] => Array
                        (
                            [_index] => employee
                            [_type] => employee_details
                            [_id] => cM1U6mEB19ahvbtRNk4F
                            [_score] => 1
                            [_source] => Array
                                (
                                    [Id] => 
                                    [First name] => 
                                    [Last name] => 
                                    [Email] => 
                                    [Phone] => 
                                    [Address] => 
                                    [Password] => 
                                    [Status] => 
                                    [createddate] => 
                                    [Updateddate] => 
                                )

                        )

                )

        )

)

Can anyone help me to parse the above array to display the id,first_name,last_name,Email,Password,Address,Status,Createddate,Updateddate all the details in html form?

1

1 Answer 1

3

Use foreach for fetching each element from the array as follows:

Assign the above array to an array variable(i.e here Im taking as $result).

foreach($result['hits']['hits'] as $each)
{
    echo $each['_source']['id'];
    echo $each['_source']['first_name'];
    echo $each['_source']['last_name'];
    echo $each['_source']['Email'];
    echo $each['_source']['Password'];
    echo $each['_source']['Address'];
    echo $each['_source']['Status'];
    echo $each['_source']['Createddate'];
    echo $each['_source']['Updateddate'];
}  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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