Quote:
Originally Posted by Mr Pheer
So I have this array like this
Code:
[location] => 2020-10-16 04:08PM -0700
City: Las Vegas
Region: Nevada
Zip Code: 89149
What I want to do, is make it into three separate variables, like this
Code:
$city = 'Las Vegas';
$region = 'Nevada';
$zipcode = '89149';
How do I do that? 
|
Pff... Now look how the PHP pro's do it ;)
Code:
preg_match('/City: (.*?)\n.*?Region: (.*?)\n.*?Zip Code: (.*?)$/s', $location, $matches);
array_shift($matches);
list($city, $region, $zipcode) = $matches;
Only 3 lines of code. We call it optimization, bro
P.S. Some people say my code sux. That because it's mostly unreadable like the one above. They write for people, I write for machines. This is why it looks so strange, but it much more compact and faster than the code, most coders are used to produce (with all those classes etc). PHP is not C++ and the server resources are very limited.