Jump to content

Does list() have a limit?


smith.james0

Recommended Posts

I am trying to us list() in the code below, the only problem with it is it only returns the first three varables, is there a limit on the list() function? I carn't find anything on php.net [img src=\"style_emoticons/[#EMO_DIR#]/excl.gif\" style=\"vertical-align:middle\" emoid=\":excl:\" border=\"0\" alt=\"excl.gif\" /]

[code]<?php
$absolute_path = pathinfo($_SERVER['SCRIPT_FILENAME']);
echo 'Path to this file: '.$absolute_path['dirname']."";


list($home,$account,$public,$visitors) = explode('/', $absolute_path['dirname']);

echo "$home <br> $account <br> $public <br> $visitors <br>";

if ( $visitors=='visitors' ) {
echo"yes";
}else{
echo "no";
}
?>[/code]

The idea of the code is to echo yes when it's in the visitors dir else echo no. I never get a value for $visitors even when it's in that dir

/home/*******/public_html/visitors

Can anyone help?

Thanks James
Link to comment
https://forums.phpfreaks.com/topic/10383-does-list-have-a-limit/
Share on other sites

I'ts because you use '/' to explode the dirname. The first '/' represents 'root', so use this:

[code]list($root,$home,$account,$public,$visitors) = explode('/', $absolute_path['dirname']);[/code]

$root will be empty.

You could also trim-off the first slash:

[code]list($home,$account,$public,$visitors) = explode('/', substr($absolute_path['dirname'],1,strlen($absolute_path['dirname'])));[/code]

But I recommend the first method.
Link to comment
https://forums.phpfreaks.com/topic/10383-does-list-have-a-limit/#findComment-38799
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.