sniperscope Posted November 4, 2011 Share Posted November 4, 2011 Hello I am facing a problem which i can not handle. I appreciate for any help. My Database is: CREATE TABLE IF NOT EXISTS `shops` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `options` text, `user_name` varchar(250) NOT NULL , PRIMARY KEY (`id`), UNIQUE KEY `user_name` (`user_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='user data stored' AUTO_INCREMENT=1 ; And some sample data as below: INSERT INTO `users` (`id`, `options`, `user_name`) VALUES (1, 'apple-orange-grape-bmw-toyota-fig-', 'user1'), (4, 'apple-tomato-pc-notebook-yellow-', 'user2'), (5, 'blue-green-orange-cdrom-', 'user3'), (6, 'orange-yellow-blue-pink-bread-', 'user4'); How can i display how many apples or green or any item selected by user? So far i tried in_array, array_count_values but seems no one is working. Regards Quote Link to comment https://forums.phpfreaks.com/topic/250417-string-search-in-an-array/ Share on other sites More sharing options...
sniperscope Posted November 4, 2011 Author Share Posted November 4, 2011 I solved. Hope this solution help someone else. $NEW_OPTION = array(); for($i=0; $i<count($OPTIONS); $i++) { $EXP = explode("-", $OPTIONS[$i]); for($j=0; $j<count($EXP); $j++) { $NEW_OPTION[] = $EXP[$j]; } } $DISPLAY_OPTIONS = array(array_count_values($NEW_OPTION)); Quote Link to comment https://forums.phpfreaks.com/topic/250417-string-search-in-an-array/#findComment-1284840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.