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 7553249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:59:47+00:00 2026-05-30T10:59:47+00:00

PHP’s list keyword is nice for taking out variables from an array $a as

  • 0

PHP’s list keyword is nice for taking out variables from an array $a as below

    $a = array(1,22);
    list($b, $c) = $a;
    var_dump("$a $b $c");

But for array $a2 in the form of key => value as below, I failed to use list

    $a2 = array('b'=>1,'c'=>22);
    list($b, $c) = $a2;
    list($bkey, $b, $ckey, $c) = $a2;
    list( list($bkey, $b), list($ckey,$c) ) = $a2;

    var_dump("$a2 $b $c");

All of the three above assignments fail. I give up.

If you know how to get the key & value in array $a2, please help!

  • 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-05-30T10:59:48+00:00Added an answer on May 30, 2026 at 10:59 am

    Following the comment of Mr Evil below (Col Shrapnel, see his profile), I never said following two ways are different, one could use either but I have advised using these methods on user-inputted data could create security problems, use it on your own risk or if there is no user-inputted data.


    It does not seem to work with associatieve arrays, you can do something like this though:

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

    Example:

    $a2 = array('b'=>1,'c'=>22);
    foreach ($a2 as $key => $value) {
         $$key = $value;
    }
    
    echo $b . '<br>';
    echo $c;
    

    Result:

    1
    22
    

    One could also use extract() function but I generally avoid it because using it on user-inputted values could create security hazards. Depending on your choice, you might want to use it or if data isn’t coming from users side.

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

Sidebar

Related Questions

PHP has a language construct list() which provides multiple variables assignment in one statement.
PHP's explode function returns an array of strings split on some provided substring. It
PHP has a very nice function, isset($variableName). It checks if $variableName is already defined
PHP (among others) will execute the deepest function first, working its way out. For
I want to count how many characters a certain string has in PHP, but
PHP's extract() function can take on one of several extract_types . But what's the
PHP having function to get values of a form using '$_POST' for 'method=post' '$_GET'
php> $a = array(a=>1,b=>0,c=>1,d=>1,e=>0); php> $b = array(); php> foreach ($a as $k =>$v){
PHP Fatal error: Out of memory (allocated 26214400) (tried to allocate 9175041 bytes) in
PHP Code <?php $content = check1\r\ncheck2\r\ncheck3\r\nend... $order = array(\r\n); $replace = \n; $content= str_replace(

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.