1

Answer:

So my issue turned out to be with the $eventValue and not the key. I was assuming the key was wrapped in brackets when it was added to the $days array but that was not the case. var_export showed me what really gets added to the array.

To solve the problem, I removed the enclosing quotes from the $eventValue as well as the trailing , comma.

Below is the original question:

Apologies as I do not know a whole lot of PHP, but I am trying to achieve something that I hope someone here can help with.

I have a loop that is finding specific days of a month to highlight on a calendar. In order for the calendar to highlight a specific day and wrap it in a class as well as a link tag, I need the array to be in this format:

$days = array(

    2 => array('/weblog/archive/2004/Jan/02', 'linked-day'),
    3 => array('/weblog/archive/2004/Jan/03', 'linked-day'),
    8 => array('/weblog/archive/2004/Jan/08', 'linked-day'),
    22 => array('/weblog/archive/2004/Jan/22', 'linked-day'),

);

Within my loop, I have these two variables:

$eventDay = substr("$str", -2, 2);
$eventValue = "array('http://example.com', 'linked-day'),";

and at the end of my loop I have this:

$days[$eventDay] = $eventValue;

The problem is, when I print_r ($days), my $eventDay key is wrapped in [] square brackets and so the day cannot be found by the calendar. I need to find a way to prevent it from being wrapped in brackets.

Perhaps I am approaching this all wrong. If someone has some suggestions I would really appreciate it.

I am using Keith Devens' PHP Calendar script to do this:

http://keithdevens.com/software/php_calendar

Thanks!

Full code:

http://pastie.org/5503664

11
  • Where is $str defined/assigned? Commented Dec 9, 2012 at 21:00
  • Have you tried var_dump() instead of print_r() ? Commented Dec 9, 2012 at 21:01
  • 2
    Could you show us the full code? The portion you showed isn't enough (eg, what is $str?). What is your actual goal for this snippet? Commented Dec 9, 2012 at 21:01
  • Can you give us a sample of print_r please... Commented Dec 9, 2012 at 21:02
  • Apologies for not posting full code. I have updated the original question with a link at the bottom to the code. Also, here is what print_r spits out: pastie.org/5503673 Commented Dec 9, 2012 at 21:05

1 Answer 1

1

Replace

$eventValue = "array('http://example.com', 'linked-day'),";

with

$eventValue = array('http://example.com', 'linked-day');

in line 44 of the pastie

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

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.