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

  • Home
  • SEARCH
  • 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 8541971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:57:06+00:00 2026-06-11T11:57:06+00:00

I have array $arr=array(a=>array(b=>123)) and I need to do with it something like this:

  • 0

I have array $arr=array("a"=>array("b"=>123))
and I need to do with it something like this:

$a='[a][b]';
echo $arr{$a};

but it doesnt work;

echo $arr[a][b]; – works fine, but it’s not what I need. =(

PHP manual says:

if you write $$a1 then the parser needs to know if you meant to use $a1 as a variable, or if you wanted $$a as the variable and then the 1 index from that variable. The syntax for resolving this ambiguity is: ${$a1} for the first case and ${$a}1 for the second. >> php manual

but “echo ${$a};” and “echo $arr{$a};” and all the other variations output nothing.

UPDATE

in short, I need to delete an element of assotiative array via form.
For example, I have $a=array(‘abc’=>’def’);
and html form

<form><input name="deleteIT" value="[abc]"></form>

So, after submitting I want to delete from $a variable $deleteIT value.

  • 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-11T11:57:07+00:00Added an answer on June 11, 2026 at 11:57 am

    Is this close enough to what you need?

    $a = "a,b";
    list( $i, $j ) = explode( ",", $a );
    echo $arr[$i][$j];
    

    Addendum: The answer above will work if the array $arr always has exactly two levels. If it might have more (or less), something like the following could work:

    function array_get_nested ( $array, $keys ) {
        $value = $array;
        foreach ( $keys as $index ) {
            $value = $value[ $index ];
        }
        return $value;
    }
    

    The function above takes two arrays as arguments: one containing the value we want, and another listing the keys we need to locate it in the first array. For example, if we have an array like this:

    $arr = array( "a" => array( "b" => array( "c" => 123 ) ) );
    

    then

    echo array_get_nested( $arr, array( "a", "b", "c" ) );
    

    would print 123.

    Converting string keys into an array suitable for the second argument to array_get_nested() depends on how the keys are formatted, but it could be as simple as calling explode() with a suitable delimiter. For example, the last line of code above could be rewritten as:

    $k = "a,b,c";
    echo array_get_nested( $arr, explode( ",", $k ) );
    

    To modify nested arrays, we can use a similar function:

    function array_set_nested ( &$array, $keys, $value ) {
        $ref =& $array;
        foreach ( $keys as $index ) {
            $ref =& $ref[ $index ];
        }
        $ref = $value;
    }
    

    Note that PHP conveniently “autovivifies” arrays for us, so we can, for example, take a previously undefined variable $foo and turn it into a three-level nested array simply with:

    array_set_nested( $foo, array( "a", "b", "c" ), 123 );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noob question here! I have an array with hashes that looks like this: arr
I have an array like this: arr = [] arr[0] = "ab" arr[1] =
I have an array like this var records:Object = {}; var arr:Array = [
I have array like this var Arr = [ 'h78em', 'w145px', 'w13px' ] I
Say I have an array like this arr = [24, 21, 25, 40, 236,
I have an array like this arr = [[24,4], [44,5],[67,1], [30, 2], [67, 2]]
I have a list comprehension operating on elements of an .NET array like obj.arr
If I have the next array: int[] arr = { 123, 243, 0, 0,
is there something like PHP: max() in javascript? lets say i have an array
Lets say I have an array like int arr[10][10]; Now i want to initialize

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.