3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fieldNames = [ 'id', 'location', 'blankets', 'sleepingbags' ]; $file = new \SplFileObject('collections1.csv', 'rb'); $file->setCsvControl(",", "\"", "\\"); $file->setFlags(\SplFileObject::READ_CSV); $sumBlankets = []; foreach ($file as $i => $line) { $row = array_combine($fieldNames, $line); $k = $row['location']; // important if (!array_key_exists($k, $sumBlankets)) { $sumBlankets[$k] = [ 'blankets' => 0, 'sleepingbags' => 0 ]; } if ( is_numeric($row['blankets']) ) { $sumBlankets[$k]['blankets'] += $row['blankets']; } if ( is_numeric($row['sleepingbags']) ) { $sumBlankets[$k]['sleepingbags'] += $row['sleepingbags']; } } var_export( $sumBlankets );
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught RuntimeException: SplFileObject::__construct(): open_basedir restriction in effect. File(collections1.csv) is not within the allowed path(s): (/tmp:/in:/etc) in /in/OOOPD:11 Stack trace: #0 /in/OOOPD(11): SplFileObject->__construct('collections1.cs...', 'rb') #1 {main} thrown in /in/OOOPD on line 11
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
65.07 ms | 401 KiB | 8 Q