简体   繁体   中英

Using if with array and adding additional area

 $contactData = array(
        'firstname'             =>  $fname,
        'lastname'              =>  $lname,
    );

I fill out my array with the information that I send from my html form with that code. I`m trying to add if so I can add additional information with it like;

 $contactData = array(
        'firstname'             =>  $fname,
        'lastname'              =>  $lname,
    );

 if ($i='5') {$contactData = array('what' => 'info');}

it probably won't work like this but I don`t know how can I get it working either. Anybody can help me with this ?

if ($i == '5') {
    $contactData['what'] = 'info';
}

正确的语法是:

if ($i=='5') {$contactData['what'] = 'info';}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM