How do I insert a variable into a PHP array?

前端 未结 3 2255
滥情空心
滥情空心 2021-02-20 05:10

I have looked for some responses on the web, but none of them are very accurate.

I want to be able to do this:

$id = \"\" . $result [\"id\"] . \"\";
$i         


        
3条回答
  •  感情败类
    2021-02-20 05:30

    Yes, you can store variables within arrays, though you'll need to remove the space between $result and the opening bracket.

    $foo = $result["bar"]; // assuming value of 'bar'
    
    $collection = array( $foo, "fizz" );
    
    foreach ( $collection as $item ) {
      // bar, fizz
      echo $item;
    }
    

提交回复
热议问题