Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - link array of key / value pairs as key => value?

Tags:

arrays

php

First I got some simple key / value pairs:

$a1['a'] = array(value1, value2);
$a1['b'] = array(value1, value2);
# ...

Now I want to use a1 as a key to other values, is that possible?

DoSomething($a1 => value);

I want to make a small search script for MySQL, my classes are almost finished. I thought to do this:

$fieldsWhereToSearch['tableWhereToSearch'] = array('bla', 'blabla');
$mySearchObject->search($fieldsWhereToSearch[tableWhereToSearch] => searchTerm);

My class would pick the matching sql, add a WHERE string with all the fields LIKE term.

like image 310
user3341388 Avatar asked Dec 19 '25 01:12

user3341388


1 Answers

No, because in PHP array keys can only be strings and integers:

The key can either be an integer or a string. The value can be of any type.

like image 102
Jon Avatar answered Dec 20 '25 17:12

Jon