ParseMe;10986996 wrote:
so in str_replace(array($docRoot,'library/config.php'), '',$thisFile;
the needles are array($docRoot) and 'library/config' all being replaced by , '',
No, the needles are $docRoot and 'library/config'.
The things stored in your array are strings, not directories. It's just that one these strings actually match some a directory path and the other may match a relative filepath, assuming you combine it with the location of the config directory. This means $docroot can be (successfully) used as arguments to for example dir().
But if you pass the array('1', $docroot) to str_replace, php doesn't make any distinction about one being a number and the other being a directory. They are both strings - they just happen to contain different characters. But all that is done is look for the string within the subject string, and when found replace that with some other string.
Consider
$docroot = $_SERVER['DOCUMENT_ROOT'];
# Here $docroot is only treated as a string, not a directory. You yourself however
# draw the conclusion that its value represent a directory path
$text = "There are 2 files in $docroot<br/>";
echo $text;
# Here '/*' is a string, but the data contained by the string means
# glob() will find all files and directories in /. Thus / is now treated like
# a directory path.
$numfiles = count(glob('/*'));
# Here both '2' and $dr are treated like strings, nothing else.
# The same goes for $numfiles and '/'.
# If '2' is found in $text, replace it with $numfiles.
# If $dr is found in $text, replace it with '/'
$newtext = str_replace(array('2', $dr), array($numfiles, '/'), $text);
echo $newtext;
# $docroot is still a string, but the data in that string allows opendir() to return a handle
# to the directory matching that location
$dir = opendir($docroot);
# $dir on the other hand is not a string, it's a resource which allows you to retrieve
# information about the file contents of that directory
ParseMe;10986996 wrote:
ok but when they say that the "root" file directory is read like an array
Well, like I said before, in the case above you do not read the root file directory at all. You are operating on strings. But you may read the root file directory and return the results as an array.
# return an array containing all files in doc root
$files = glob($_SERVER['DOCUMENT_ROOT'] . '/*');
ParseMe;10986996 wrote:
usually arrays are composed of many units
Yes, arrays can contain many elements. In your case the array has two elements.