php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52336 You can't use multidimensional arrays in functions which support arrays.
Submitted: 2010-07-14 13:53 UTC Modified: 2010-09-21 17:58 UTC
From: j dot pruehsing at web dot de Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Windows + Linux
Private report: No CVE-ID: None
 [2010-07-14 13:53 UTC] j dot pruehsing at web dot de
Description:
------------
The documentation for functions like str_replace says, that you can use an array as subject. Multidimensional arrays are not excluded, but if you use them nothing happens. This bug is reproducable with ALL functions which should support the use of array. If this is wanted behaviour you should edit the documentation.

Test script:
---------------
$testarray = array(array('bla',  'blub'),array('blub', 'bla'));
$testarray = str_replace('bla', 'blub', $testarray); //doesn't work
print_r($testarray);

echo('<br>');
for($i=0; $i<count($testarray); $i++)
{
  $testarray[$i] = str_replace('bla', 'blub', $testarray[$i]); //works
}
print_r($testarray);


Expected result:
----------------
-only array output of 'blub'

Actual result:
--------------
Array ( [0] => Array ( [0] => bla [1] => blub ) [1] => Array ( [0] => blub [1] => bla ) )
Array ( [0] => Array ( [0] => blub [1] => blub ) [1] => Array ( [0] => blub [1] => blub ) ) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-21 17:58 UTC] markskilbeck@php.net
-Status: Open +Status: Bogus
 [2010-09-21 17:58 UTC] markskilbeck@php.net
This isn't a bug.

The documentation says you can pass an array of needles and an array of 
replacements. It's just common-sense that these needles/replacements would be 
scalar types (not an array).
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jul 31 04:01:24 2021 UTC