3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('ROWS_PER_PAGE', 10); function display_table($fields, $data, $rows, $page){ if(isset($_GET['page'])){ $page = $_GET['page']; } else { $page = 1; } $firstRecord = ($page - 1) * ROWS_PER_PAGE; $pageNumbers = ceil($rows / ROWS_PER_PAGE); echo '<div class="table-responsive w-75 mx-auto py-3"> <table class="table table-dark table-bordered table-sm"> <thead> <tr>'; foreach($fields as $key){ echo '<th class="py-2">' . $key . '</th>'; } echo '</tr> </thead> </tbody>'; $keys = array_keys($fields); $lastRecord = min($firstRecord + ROWS_PER_PAGE, $rows); for($record = $firstRecord; $record < $lastRecord; $record++){ $row = $data[$record]; echo '<tr>'; for($recordCount = 0; $recordCount < count($keys); $recordCount++){ $column = $keys[$recordCount]; echo '<td class="py-2">' . $row[$column] . '</td>'; } echo '</tr>'; } echo '</tbody> </table'; for($pages = 1; $pages <= $pageNumbers; $pages++){ echo '<a class="btn btn-dark mx-1" href=?page=' . $pages . '</a>'; } } $fields = array( "id" => "Id", "emailaddress" => "Email", "firstname" => "First Name", "lastname" => "Last Name", "salesperson" => "Salesperson", "phonenumber" => "Phone Number", "extension" => "Extension", "type" => "Type" ); $data = array( array('id' => 1, 'emailaddress' => 'user1@example.com', 'firstname' => 'User', 'lastname' => 'One', 'salesperson' => 'y', 'phonenumber' => '1235556789', 'extension' => '1', 'type' => 'a') , array('id' => 2, 'emailaddress' => 'user2@example.com', 'firstname' => 'User', 'lastname' => 'Two', 'salesperson' => 'y', 'phonenumber' => '1235556789', 'extension' => '2', 'type' => 'a') ); display_table($fields, $data, 2, 1);
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13, 8.1rc1 - rc3
<div class="table-responsive w-75 mx-auto py-3"> <table class="table table-dark table-bordered table-sm"> <thead> <tr><th class="py-2">Id</th><th class="py-2">Email</th><th class="py-2">First Name</th><th class="py-2">Last Name</th><th class="py-2">Salesperson</th><th class="py-2">Phone Number</th><th class="py-2">Extension</th><th class="py-2">Type</th></tr> </thead> </tbody><tr><td class="py-2">1</td><td class="py-2">user1@example.com</td><td class="py-2">User</td><td class="py-2">One</td><td class="py-2">y</td><td class="py-2">1235556789</td><td class="py-2">1</td><td class="py-2">a</td></tr><tr><td class="py-2">2</td><td class="py-2">user2@example.com</td><td class="py-2">User</td><td class="py-2">Two</td><td class="py-2">y</td><td class="py-2">1235556789</td><td class="py-2">2</td><td class="py-2">a</td></tr></tbody> </table<a class="btn btn-dark mx-1" href=?page=1</a>

preferences:
43.89 ms | 462 KiB | 5 Q