Check for duplicate entries in a PHP array -


Is there a tool that I can run PHP code, so I will be typed in something like this? $ myarray = array ('foo' = & gt; 'hello', 'bar' = & gt;'byeby ',' afoo '=>' hello again '// & Lt; = Duplicate key on this line is required;

EDIT: I want something other than ownership

You are overwriting your array keys, so PHP only pickup on last entry for 'af' $ Arr = array ('foo' = & gt; 'hello', 'bar' = & gt; goodbye ',' foo '=>' hello again '/ / & Lt; = Requires duplicate key on this line); Print_r ($ arrivals); Blockquote> $ arr = array ('foo' = & gt; 'hello', 'bar' = & gt;'byeby ',' foo3 '=>' hello again '/ / / & Lt; = Required duplicate key on this line); Print_r ($ arrivals); Array ([fu] => Hello [Bar] = & gt; Bye [foo3] => Hello again)

Returns:

Also move through a foreach loop (through its array)

  $ arr = array ('foo' = & gt; 'hello ',' Bar '= & gt;' Bye ',' Foo '=>' Hello again '// & lt; = Required duplicate key on this line); Forex Currency ($ arr AS Keys = & gt; $ Value) {$ echo $ keys; Echo "& lt; br & gt;"; }   

returns:

  bar foo   

overall ethics:

your array key Overwriting, so PHP does not accept a duplicate key.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -