0

So I want to try something a little different.

Let's say someone puts in an input text box the following two examples.

"name:Justin"

I want to go into an array
Index| Col Val

[0] Name Justin

In second Example "name:Justin,state:CA"

[0] Name Justin [1] State CA

Basically I have a page where Im using text inputs to query a remote database. I was thinking of doing some conditionals so that they can specify which column to search. Then pushing that to do multiple column searches but I need a way to read the results. I figured out how to do it for 1 result but I'm drawing a blank on how to do it if they want to do multiple.

Thoughts?

1
  • 1
    array_map(function($kv) {return explode(":",$kv);},explode(",",$input)); should get you started. Commented Nov 5, 2014 at 16:26

1 Answer 1

4

Use explode() to generate an array and array_map() to replace : by space. Example:

$str = 'name:Justin,state:CA';
$arr = explode(',', $str);
$result = array_map(function($v){return str_replace(':', ' ', $v);},$arr);

print '<pre>';
print_r($result);
print '</pre>';
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.