search

Home  >  Q&A  >  body text

Use PHP's foreach command to convert all PHP input into an array and set it to a JSON file in the form of key-value pairs - Solved

<p>I have a page that contains multiple radio buttons and I use a foreach loop to loop through the names of all radio buttons and another foreach loop at the top of the page to get the names of all radio buttons as keys and values. </p> <pre class="brush:php;toolbar:false;"><?php $radios=["name"=>"Display name","profile"=>"Display profile","phone"=>"Display phone number"]; $setting=[ "Some text"=>"its value"] foreach($radios as $key=>$value){ $setting[]=$value=>$_POST[$value]; } // it won't work ?></pre>
P粉883223328P粉883223328510 days ago464

reply all(1)I'll reply

  • P粉205475538

    P粉2054755382023-08-10 12:07:58

    Not sure what you want to achieve, but that code doesn't look valid:

    $setting[]=$value=>$_POST[$value];

    reply
    0
  • Cancelreply