I need some help with the foreach loop. Say I have this method:
public function showPaymentDetails() {
$data = array("name" => $this->name,
"lastname" => $this->lastname,
"email" => $this->email,
"company" => $this->company,
"event_name" => $this->event_name,
"event_price" => $this->event_price,
"uniqid" => $this->uniqid,
"mobile" => $this->mobile,
"travel" => $this->travel,
"job" => $this->job,
"how_hear" => $this->how_hear,
"geusts" => $this->guests,
"slider_network" => $this->slider_network,
"slider_invest" => $this->slider_invest,
"slider_investors" => $this->slider_investors,
"gender" => $this->gender
);
return $data;
}
Now i want to assign each value of an array to a variable. This is what I do:
$i = 0;
foreach($data as $row[$i]) {
$row[$i];
$i++;
}
echo $row[0];
echo $row[1];
echo $row[2];
As you can see I am assigning values to $row[]. Which is really bad. How can I assign those values to such variable names as $name, $lastname etc.
Thanks!
extract($data);? php.net/extract Why do you want to do this?$data as $row[$i]supposed to do? Maybe you just want$row = array_values($data);?