3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testHeader = ['Mold SKU', 'Title', 'Category', 'Tags']; $testRows = []; $testRows[] = ['12MM-SM-SQ', '12mm Squares', 'Earings|Earings > Fishhooks','square']; $testRows[] = ['12MM-SQ-HOLLOW-DROP', 'Square Hollow Drop Studs', 'Earings|Earings > Studs','square']; $testRows[] = ['Example SKU', 'Example Title', 'Example|Sub|Whatever|category','tag1|tag2|tag3']; $testArray = [$testHeader, ...$testRows]; $fp = fopen('php://memory', 'w+'); foreach ($testArray as $testRow) { fputcsv($fp, $testRow); } rewind($fp); // ABOVE IS ONLY FOR TESTING HERE! ------------------------------------- // $fp = fopen($skufileurl, 'r'); // <-- you will use this! $termName = 'Example SKU'; $csvRows = []; $csvHeader = fgetcsv($fp); while ($csvRow = fgetcsv($fp)) { $keyedCsvRow = array_combine($csvHeader, $csvRow); if ($keyedCsvRow['Mold SKU'] === $termName) { $keyedCsvRow['Category'] = explode('|', $keyedCsvRow['Category']); $keyedCsvRow['Tags'] = explode('|', $keyedCsvRow['Tags']); $finalArray = $keyedCsvRow; break; } } var_dump($finalArray);
Output for 8.4.1 - 8.4.14
Deprecated: fputcsv(): the $escape parameter must be provided as its default value will change in /in/hg07O on line 13 Deprecated: fputcsv(): the $escape parameter must be provided as its default value will change in /in/hg07O on line 13 Deprecated: fputcsv(): the $escape parameter must be provided as its default value will change in /in/hg07O on line 13 Deprecated: fputcsv(): the $escape parameter must be provided as its default value will change in /in/hg07O on line 13 Deprecated: fgetcsv(): the $escape parameter must be provided as its default value will change in /in/hg07O on line 22 Deprecated: fgetcsv(): the $escape parameter must be provided as its default value will change in /in/hg07O on line 23 Deprecated: fgetcsv(): the $escape parameter must be provided as its default value will change in /in/hg07O on line 23 Deprecated: fgetcsv(): the $escape parameter must be provided as its default value will change in /in/hg07O on line 23 array(4) { ["Mold SKU"]=> string(11) "Example SKU" ["Title"]=> string(13) "Example Title" ["Category"]=> array(4) { [0]=> string(7) "Example" [1]=> string(3) "Sub" [2]=> string(8) "Whatever" [3]=> string(8) "category" } ["Tags"]=> array(3) { [0]=> string(4) "tag1" [1]=> string(4) "tag2" [2]=> string(4) "tag3" } }
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27
array(4) { ["Mold SKU"]=> string(11) "Example SKU" ["Title"]=> string(13) "Example Title" ["Category"]=> array(4) { [0]=> string(7) "Example" [1]=> string(3) "Sub" [2]=> string(8) "Whatever" [3]=> string(8) "category" } ["Tags"]=> array(3) { [0]=> string(4) "tag1" [1]=> string(4) "tag2" [2]=> string(4) "tag3" } }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '...' (T_ELLIPSIS), expecting ']' in /in/hg07O on line 9
Process exited with code 255.

preferences:
156.2 ms | 410 KiB | 5 Q