Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Store and Update Multidimensional Array in PHP

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.93k
    Answer it

    I want to store and update multidimensional array data 

     

    The data is coming in this form 

     

    1. array:7 [
    2. "address_heading" => array:2 [
    3. 0 => "address_heading_1"
    4. 1 => "address_heading_1"
    5. ]
    6. "address_subheading" => array:2 [
    7. 0 => "address_subheading_1"
    8. 1 => "address_subheading_2"
    9. ]
    10. "address" => array:2 [
    11. 0 => "address_1"
    12. 1 => "address_2"
    13. ]
    14. "mobile_number" => array:2 [
    15. 0 => "1234568780"
    16. 1 => "1234568555"
    17. ]
    18. "email_id" => array:2 [
    19. 0 => "test@mail.com"
    20. 1 => "test@mail.com"
    21. ]
    22. "contact_id" => array:1 [
    23. 0 => null
    24. ]
    25. "iframe" => "google map"
    26. ]

     

    Anyone help

 1 Answer(s)

  • hi,
    you can set or change as follows:- 
    1. mainArray[ key or keyName ] = value;
    2. mainArray[ key or keyName ][next dimension key or keyName] = value; 
    3. can use php foreach loop to modify or access child element in array
    4. can use php inbuilt array functions like array walk or array walk recursive.

    foreach example:- 
    foreach($address as &$add){
        if($add['address'][0] === 'address_main'){
            $add['1'] = 'new_address;
        }
    }
    please comment if further information required
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: