0
$class = array('c1', 'c2', 'c3', 'c4');

$people['c1'] = 'A';
$people['c2'] = 'B';
$people['c3'] = 'C';
$people['c4'] = 'D';

foreach ($class as $key)
{
  echo "Name: ".$people[$key]."\n"; 
}

result :

A
B
C
D

now when i add new 50 values to $class and $people

in some host everthing fine, but with hostpapa.com

looping only run well 36 time.

from 36+ , some values are null ( $people[$key] = null )

I don't know why. Maybe a settings limit the array ?

Note: Suhosin is instlled on this host

12
  • why didn't you ask hostpapa.com ? Commented Jul 14, 2011 at 9:25
  • 1
    You can't limit arrays in any normal version of PHP. Only memory limits apply, but I doubt that's a problem with 36 tiny strings. Commented Jul 14, 2011 at 9:25
  • 2
    Additionally, show us your code that "adds" 50 values and causes null values. It's more likely to be a typo. Commented Jul 14, 2011 at 9:27
  • 1
    don't use c1 as a key, unless c1 is a defined constant. use 'c1'. Otherwise PHP checks if c1 is defined constant, then converts it to string 'c1', issuing a warning that c1 is not defined, which is written to logs and eventually outputed (depending on the settings). It's 4x slower. Commented Jul 14, 2011 at 9:33
  • 1
    @Chameron my point is, that if the id is a string, you have to use '' around the string :) Just a note, as this is a very common mistake. Commented Jul 14, 2011 at 9:36

3 Answers 3

2

My guess would be that the hosting company may be running the "security hardened" version of PHP known as Suhoshin.

Suhoshin implements a large number of security hardening features for PHP, including the ability to limit stuff like field lengths and array sizes -- see http://www.hardened-php.net/suhosin/configuration.html

It may be that something in your code is triggering one of Suhoshin's filters.

Either way, this sounds like something you need to discuss with your hosting company.

Sign up to request clarification or add additional context in comments.

Comments

0
$class = array('c1', 'c2', 'c3', 'c4');

$people[c1] = 'A';
$people[c2] = 'B';
$people[c3] = 'C';
$people[c4] = 'D';

foreach ($class as $key)
{
  if(key() > 36) {
    break;
  }
  echo "Name: ".$people[$key]."\n"; 

I hadn't test this, but it's must work. }

Comments

0

Depending on what you do in for foreach statement it can be due to a limitation in execution time limit of you script.

If you do relatively timeconsuming stuff per loop in the foreach this could easily add up to minutes and this can run into the execution time limit in the php.ini.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.