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
create table coordinates (x double, y double)

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

Copy Clear
Copy Format Clear
<?php use Carbon\Carbon; $GLOBALS['db'] = $db; function insertData() { for ($i=0; $i<100; $i++) for ($row=1; $row<=10; $row++) for ($col=1; $col<=10; $col++) $coords[] = ['x'=>floatval($row.'.'.rand(1, 99)), 'y'=>floatval($col.'.'.rand(1,99))]; $GLOBALS['db']->table('coordinates')->insert($coords); } for ($i=0; $i<10; $i++) insertData(); $startTime = Carbon::now(); $selected = $db->table('coordinates') ->where('x', '>=', 1) ->where('x', '<', 11) ->where('y', '>=', 1) ->where('y', '<', 11) ->get()->toArray(); foreach($selected as $entry) { $formattedX = explode('.', $entry->x, 2)[0]; $formattedY = explode('.', $entry->y, 2)[0]; //$formatted[$formattedX][$formattedY]['entyties'][] = $entry; $formatted[$formattedX][$formattedY]['count'] += 1; } $time = Carbon::now()->floatDiffInSeconds($startTime); print('time: '.$time); print(PHP_EOL); print('count data: '.count($selected)); print(PHP_EOL); //print_r($formatted);
Copy Clear