Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize | SQLize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $lines = [ '4e84||some text||category A', 'f17b||words words||category B', 'f7ac||some more text here||category B', '8683||text text||category C', 'b010||more text||category A', 'fcc4||more text||category B', 'we47||more text||category C', '08ml||more text||category A' ]; $split_lines = []; // first - split lines and put them into array // using third parameter as key foreach ($lines as $line) { $split_lines[] = explode('||', $line); } // sort array by function usort($split_lines, fn($a,$b)=>$a[2]<=>$b[2]); // show array as table foreach ($split_lines as $line) { echo '<tr>'; echo '<td>'.$line[0].'</td>'; echo '<td>'.$line[1].'</td>'; echo '<td>'.$line[2].'</td>'; echo '</tr>' . PHP_EOL; } ?>
Copy Clear