Last active
March 5, 2021 12:51
-
-
Save tim-cotten/5acaabbe338f98a50b637ecdcb704ee8 to your computer and use it in GitHub Desktop.
PHP Bugs: Arrays Don't Like Undefined Offsets (Example D)
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 ($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