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

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

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

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) { $splited_line = explode('||', $line); $split_lines[$splited_line[2]] = $splited_line; } // sort array by keys ksort($split_lines); // 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