Created
March 5, 2021 12:56
-
-
Save tim-cotten/8e7d3316d7ab0e72e6431b60b0940162 to your computer and use it in GitHub Desktop.
PHP Bugs: Arrays Don't Like Undefined Offsets (Example E)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Set relative product URLs | |
foreach ($products as &$product) { | |
$url = "&product_id={$product['id']}"; | |
$name = explode(" -- ", $product['name']); // like: Chocolates -- 587 | |
$url .= "&name={$name[0]}"; | |
if (!empty($name[1])) { | |
$name[1] = str_pad($name[1], 8, "0", STR_PAD_LEFT); // format as 00000587 | |
$url .= $name[1]; | |
} | |
$product['url'] = $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment