Skip to main content
Inspiring
December 7, 2013
解決済み

PHP array/function problem

  • December 7, 2013
  • 返信数 1.
  • 885 ビュー

I'm having a problem trying to understand why a predefined array is not being echoed/print_r when requested from inside a function.

the array is global(?) by being defined outside the function(s). I can't seem to see why it wont show the array?

It works outside the function

$mondayset=array("setone", "settwo", "setthree", "setfour");

$tuesdayset=array(""setfive", "setsix", setseven");

function dosets ($pubdate)

          {

  $caledardate = explode("/", $pubdate);

  $timestamp = strtotime("$caledardate[2]"."-"."$caledardate[0]"."-"."$caledardate[1]");

  if(date('D', $timestamp) === 'Mon')

     {

          echo "It is Monday today\n";

          print_r($mondayset);


     }

$thedate = 12/2/2013

dosets($thedate)

このトピックへの返信は締め切られました。
解決に役立った回答 bregent

Variables inside functions have a local scope.

http://php.net/manual/en/language.variables.scope.php

You can pass the array to the function if you want to reference it.

返信数 1

bregent解決!
Participating Frequently
December 7, 2013

Variables inside functions have a local scope.

http://php.net/manual/en/language.variables.scope.php

You can pass the array to the function if you want to reference it.

JonnyDL作成者
Inspiring
December 7, 2013

Wow Ok that link worked. got ot to work thanks!

Participating Frequently
December 7, 2013

Great. You're welcome.