Jump to content

String search in an array


sniperscope

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/250417-string-search-in-an-array/
Share on other sites

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));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.