PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE Users ( User_id int, Value varchar(255) ); INSERT INTO Users VALUES (123, 'a:4:{i:0;s:3:"615";i:1;s:3:"619";i:2;s:3:"918";i:3;s:3:"570";}'), (12, 'a:3:{i:0;s:2:"23";i:1;s:3:"615";i:2;s:3:"918";}'), (143, 'a:2:{i:0;s:3:"918";i:1;s:3:"125";}');
Copy Clear
Copy Format Clear
<?php $query = "SELECT * FROM Users;"; $stmt = $pdo->prepare($query); $stmt->execute(); $users = $stmt->fetchAll(PDO::FETCH_ASSOC); //Unserialize and join user arrays $count_users = array_reduce( $users, function($res, $u) { return array_merge($res, unserialize($u['Value'])); }, [] ); //Print count values print_r(array_count_values($count_users));
Show:  
Copy Clear