Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Remove Square Brackets from Array Key
    primarykey
    data
    text
    <p><strong>Answer:</strong></p> <p>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.</p> <p>To solve the problem, I removed the enclosing quotes from the $eventValue as well as the trailing , comma.</p> <p><strong>Below is the original question:</strong></p> <p>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.</p> <p>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:</p> <pre><code>$days = array( 2 =&gt; array('/weblog/archive/2004/Jan/02', 'linked-day'), 3 =&gt; array('/weblog/archive/2004/Jan/03', 'linked-day'), 8 =&gt; array('/weblog/archive/2004/Jan/08', 'linked-day'), 22 =&gt; array('/weblog/archive/2004/Jan/22', 'linked-day'), ); </code></pre> <p>Within my loop, I have these two variables:</p> <pre><code>$eventDay = substr("$str", -2, 2); $eventValue = "array('http://example.com', 'linked-day'),"; </code></pre> <p>and at the end of my loop I have this:</p> <pre><code>$days[$eventDay] = $eventValue; </code></pre> <p>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.</p> <p>Perhaps I am approaching this all wrong. If someone has some suggestions I would really appreciate it.</p> <p>I am using Keith Devens' PHP Calendar script to do this:</p> <p><a href="http://keithdevens.com/software/php_calendar" rel="nofollow">http://keithdevens.com/software/php_calendar</a></p> <p>Thanks!</p> <p><strong>Full code:</strong></p> <p><a href="http://pastie.org/5503664" rel="nofollow">http://pastie.org/5503664</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload