3v4l.org

run code in 300+ PHP versions simultaneously
<?php $database = 'id|name_sname|identity|address|region|hours|destination|price; -------------------------------------------------------------------- 1|Test Mod|123456789|husi, stanilesti, vaslui|HUSI - IASI|20:00|HUSI|100; 2|Jhon Doe|123456789|husi, stanilesti, vaslui|HUSI - IASI|20:00|HUSI|100; 3|Himel Rana|123456789|husi, stanilesti, vaslui|HUSI - IASI|20:00|HUSI|100; 4|Ezra Mod|123456789|husi, stanilesti, vaslui|HUSI - IASI|20:00|HUSI|100; 5|Keven Korp|123456789|husi, stanilesti, vaslui|HUSI - IASI|20:00|HUSI|100; 6|Tamim Iqbal|123456789|husi, stanilesti, vaslui|HUSI - IASI|20:00|HUSI|100;'; //$data = file_get_contents("database.txt"); //read the file $rows = explode("\n", $database); //create array separate by new line $rows = array_map("trim", $rows); // for removing any unwanted space $rowCount = count($rows); // Count your database rows function CountCol($data){ $col = explode("|", $data); return count($col); } // Creating array from our text database // in our database first two rows are not needed so I am skipig this // by using i = 2 // and $rowCount -1 because of our array start from 0 but count start from 1 // adding $id[$i-2] and like other because of we have started our first loop from 2 and I want to // create my new array starting from 0 . for ($i=2; $i <$rowCount-1 ; $i++) { for ($j=0; $j < CountCol($rows[$i]) ; $j++) { $column = explode("|", $rows[$i]); $id[$i-2] = $column[0]; $name_sname[$i-2] = $column[1]; $identity[$i-2] = $column[2]; $address[$i-2] = $column[3]; $region[$i-2] = $column[4]; $hours[$i-2] = $column[5]; $destination[$i-2] = $column[6]; $price[$i-2] = $column[7]; } } // let's print our data // I am using 3 here because of we have no need first 2 rows and our array start from 0 for ($i=0; $i < $rowCount-3 ; $i++) { echo "ID: ".$id[$i] ."\r\n"; echo "name_sname: ".$name_sname[$i]."\r\n"; echo "identity: ".$identity[$i] ."\r\n"; echo "address: ".$address[$i] ."\r\n"; echo "region: ".$region[$i] ."\r\n"; echo "hours: ".$hours[$i] ."\r\n"; echo "destination: ".$destination[$i] ."\r\n"; echo "price: ".$price[$i] ."\r\n"; } // // get it like below echo "printing information using id number \r\n"; echo $name_sname[0]; // here 0 is row number or id number echo "\r\n"; echo $name_sname[1];// here 1 is row number or id number echo "\r\n"; echo $id[0]; ?>
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
ID: 1 name_sname: Test Mod identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; ID: 2 name_sname: Jhon Doe identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; ID: 3 name_sname: Himel Rana identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; ID: 4 name_sname: Ezra Mod identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; ID: 5 name_sname: Keven Korp identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; printing information using id number Test Mod Jhon Doe 1
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 ID: 1 name_sname: Test Mod identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; ID: 2 name_sname: Jhon Doe identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; ID: 3 name_sname: Himel Rana identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; ID: 4 name_sname: Ezra Mod identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; ID: 5 name_sname: Keven Korp identity: 123456789 address: husi, stanilesti, vaslui region: HUSI - IASI hours: 20:00 destination: HUSI price: 100; printing information using id number Test Mod Jhon Doe 1

preferences:
231.62 ms | 403 KiB | 300 Q