3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $value = "100% Wool"; $separators = [ "/", ",", "&", " AND " ]; $value = str_replace($separators, "|", $value); $candidates = explode("|", $value); foreach($candidates as $candidate) { $percentage = (count($candidates) == 1) ? "100%" : null; if($candidate = trim($candidate)){ if(strpos("%", $candidate) !== false) { list($percentage, $material) = explode("%", $candidate); $percentage .= "%"; } else { $material = $candidate; } $entities = $this->mapping['material']; if($id = $this->exact($material, $entities)) { $material = [ 'material_id' => $id, 'percentage' => $percentage ]; $product['materials'][] = $material; } else { } } } print_r($product['materials']);
based on VXgil
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/EKvX7:23 Stack trace: #0 {main} thrown in /in/EKvX7 on line 23
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Fatal error: Using $this when not in object context in /in/EKvX7 on line 23
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/EKvX7 on line 4
Process exited with code 255.