I want to do something like bellow using php:
$turl=array(trim($params->get('c2')));
$tname=array(trim($params->get('cn2')));
and want to display each $turl with each $tname.
I tried like this:
$result=array_combine($turl,$tname);
print_r($result);
but given result as:
Array ( [http://184.107.144.218:8282/,http://184.107.144.218:8082/] => ABC Radio,AHH Radio )
But I want like this:
Array ( [http://184.107.144.218:8282/=> ABC Radio,
http://184.107.144.218:8082/=> AHH Radio )
Thanks in advance
maybe you want to use a code similar to this:
The error seems to be into the $turl and $tname arrays creation as array combine should work as intended
Obviously I would add several checks, as, for example, Have the two arrays the same size?
Addendum
In your comment you give me a specimen of what
$params->getreturns if called with parameters ‘c2’ and ‘cn2’.The example code I gave you do what required, or at leas what I was thinking you are trying to obtain. A different code with a different result is:
or, if you want to obtains a single string:
You can obtain any desired result modifying one of the previous example.
To encase the results in an option you need a slight variation of the array_map user function:
PHP < 5.3 version
Put this function declaration somewhere in the global scope
and then your code will become:
If possible I won’t clutter the global namespace with function like formatOption,
but when anonymous function are not available
Reference: