View Single Post
Old 10-19-2020, 01:22 AM  
just a punk
So fuckin' bored
 
just a punk's Avatar
 
Industry Role:
Join Date: Jun 2003
Posts: 32,384

Quote:
Originally Posted by Mr Pheer View Post
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.
__________________
Obey the Cowgod
just a punk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote