Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:23:09+00:00 2026-06-10T21:23:09+00:00

Not sure why this is occurring: Basically, I have an array that contains the

  • 0

Not sure why this is occurring: Basically, I have an array that contains the following arrays, see var_dump:

array(2) { 
  [0]=> array(1) { 
    [0]=> string(3) "ivr" 
  } 
  [1]=> array(1) { 
    [0]=> string(9) "ivr_dests" 
  } 
}

Obviously this data is kind of redundant, but it’s what was returned while getting values with xpath. So I’m doing a foreach to loop through the first array() and assign it’s nested array values in the first array.

Basically, it should return this:

array(2) {
  [0]=> string(3) "ivr"
  [1]=> string(9) "ivr_dests"
}

So here is what I’ve setup:

foreach($arr as $key => $arr2){
    $arr2[$key] = $arr2[$key][0];
    unset($arr2[$key][0]); //This returns Fatal error: Cannot unset string offsets
//if I comment out the unset(), $arr[$key] returns the same value as it did (multidim array)
};

        //I tried this too:
$i=0;
foreach($arr as $arr2){
  $arr2[$i] = $arr2[$i][0];
  $i++;
}

Any ideas what I’m doing wrong? Should I go about this another way?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:23:11+00:00Added an answer on June 10, 2026 at 9:23 pm

    You don’t need the unset, you are overriding the outer parameters with the value of the inner array as opposed to the whole array.

    $a1 = array("ivr");
    $a2 = array("ivr2");
    
    $a3 = array($a1, $a2);
    
    foreach($a3 as $key => $value){
        $a3[$key] = $a3[$key][0];
        //unset($arr2[$key][0]);
    };
    
    var_dump($a3);
    

    I think you are confused about how foreach works.

    foreach($array as $key => $value)
    {
      echo $key;
      echo $value;
    }
    

    will display the key and value for each key/value pair in an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure this is possible, but looking to write a script that would return
Disclaimer: not sure this is WordPress related or not. I'm following a simple tutorial
I have a legacy database that I connect to and not sure why I
I think I may have overlooked something here, but I'm not sure why this
Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8
I'm not sure this is the right forum if it's not please feel free
I'm not sure this is even possible but I know if it is, the
I am not sure this can be done at all... Background: I am constructing
I'm not sure this is possible, but in ruby, you can dynamically call a
I'm not sure this is possible, but is there a syntax to be used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.