Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>maybe you want to use a code similar to this:</p> <pre><code>$turl = explode(',',trim($params-&gt;get('c2'))); $tname = explode(',',trim($params-&gt;get('cn2'))); $result=array_combine($turl,$tname); print_r($result); </code></pre> <p>The error seems to be into the $turl and $tname arrays creation as array combine should work as intended</p> <p>Obviously I would add several checks, as, for example, Have the two arrays the same size?</p> <p><strong><em>Addendum</em></strong><br> In your <a href="https://stackoverflow.com/questions/9794274/combined-2-array-data/9794405#comment12497632_9794405">comment</a> you give me a specimen of what <code>$params-&gt;get</code> returns if called with parameters 'c2' and 'cn2'.</p> <pre><code>$params-&gt;get('c2')="hoicoimasti.com,google.com" $params-&gt;get('cn2')="hoicoi,google". </code></pre> <p>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:</p> <pre><code>$turl = explode(',',trim($params-&gt;get('c2'))); $tname = explode(',',trim($params-&gt;get('cn2'))); $result=array_map(function($x,$y){return $x.','.$y;},$turl,$tname); print_r($result); </code></pre> <p>or, if you want to obtains a single string:</p> <pre><code>$result=join(',',array_map(function($x,$y){return $x.'=&gt;'.$y;},$turl,$tname)); print_r($result); </code></pre> <p>You can obtain any desired result modifying one of the previous example.</p> <p>To encase the results in an option you need a slight variation of the array_map user function:</p> <pre><code>$result=join("\n",array_map( function($x,$y){ return "&lt;option&gt;$x=&gt;$y&lt;/option&gt;"; }, $turl, $tname )); print_r($result); </code></pre> <p><strong>PHP &lt; 5.3 version</strong><br> Put this function declaration somewhere in the global scope</p> <pre><code>function formatOption($x,$y){ return "&lt;option&gt;$x=&gt;$y&lt;/option&gt;"; }; </code></pre> <p>and then your code will become:</p> <pre><code>$result=join("\n",array_map( 'formatOption', $turl, $tname)); print_r($result); </code></pre> <p>If possible I won't clutter the global namespace with function like <em>formatOption</em>, but when anonymous function are not available </p> <p><strong>Reference</strong>:</p> <ul> <li><a href="http://www.php.net/array_map" rel="nofollow noreferrer">array_map</a></li> <li><a href="http://www.php.net/join" rel="nofollow noreferrer">join</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload