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.79k
    Answer it

    I want to store and update multidimensional array data 

     

    The data is coming in this form 

     

    array:7 [
      "address_heading" => array:2 [
        0 => "address_heading_1"
        1 => "address_heading_1"
      ]
      "address_subheading" => array:2 [
        0 => "address_subheading_1"
        1 => "address_subheading_2"
      ]
      "address" => array:2 [
        0 => "address_1"
        1 => "address_2"
      ]
      "mobile_number" => array:2 [
        0 => "1234568780"
        1 => "1234568555"
      ]
      "email_id" => array:2 [
        0 => "test@mail.com"
        1 => "test@mail.com"
      ]
      "contact_id" => array:1 [
        0 => null
      ]
      "iframe" => "google map"
    ]

     

    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
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: