Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've search up and down but can't seem to get this array to function properly, I'm missing something simple but unable to figure out what exactly.

<?php

    $dates2 = 'Aug 30, 2013';
    $dates3 = 'Sep 13, 2013';

    $cards[0] = array(
        'card' => 'Discover',
        'pay'  => '875', 
        'when' => array('
            'Sep 03, 2013', 
            'Oct 03, 2013', 
            'Nov 03, 2013',
            'Dec 03, 2013'
        ),                    
    );
    $cards[1] = array(
        'card' => 'Visa',
        'pay'  => '375', 
        'when' => array(
            'Sep 23, 2013', 
            'Oct 23, 2013', 
            'Nov 23, 2013',
            'Dec 23, 2013'
        ),        
    );
    $cards[2] = array(
        'card' => 'Mastercard',
        'pay'  => '1025', 
        'when' => array(
            'Sep 12, 2013', 
            'Oct 13, 2013', 
            'Nov 13, 2013',
            'Dec 13, 2013'
        ),
    );
    $cards[3] = array(
        'card' => 'Amex',
        'pay'  => '650', 
        'when' => array(
            'Aug 25, 2013', 
            'Sep 05, 2013', 
            'Oct 25, 2013',
            'Nov 25, 2013'
        ),
    );

    for ($i=0; $i<=3; $i++){  
        if ($cards[$i]['when'][$i] > $dates2 && ($cards[$i]['when'][$i] < $dates3) or ($cards[$i]['when'][$i] == $dates2)) {
            print "<tr>
                <td>$cards[$i]['card']</td>
                <td><input class='amount' size='3' value='$cards[$i]['pay']'></td>
            </tr>";                                  
         } 
     }

?>

Output: Array['card'] Array['card'] Array['card'] Array['card']

share|improve this question
1  
Curious as to why it got a down vote? If you're going to downvote someone, you should provide feedback as to why. – Brant Aug 16 at 20:59

3 Answers

You need to concatenate the variables or reset them then print them.

DEMO PHPfiddle http://phpfiddle.org/main/code/ia5-dh6

This is with them reset

DEMO PHPfiddle http://phpfiddle.org/main/code/7if-nd3

note i have added the missing table tags too

$CardType = $cards[$i]['card'];
$Payment = $cards[$i]['pay'];

print "<tr>
         <td>$CardType</td>
         <td><input class='amount' size='3' value='$Payment'></td>
       </tr>";  
share|improve this answer

It's your output statement, this fixed it for me:

print "<tr><td>" . $cards[$i]['card'] . "</td><td><input class='amount' size='3' value='" . $cards[$i]['pay'] . "'></td></tr>";
share|improve this answer

Reference: Variable parsing

Variable parsing

When a string is specified in double quotes or with heredoc, variables are parsed within it.

There are two types of syntax: a simple one and a complex one. The simple syntax is the most common and convenient. It provides a way to embed a variable, an array value, or an object property in a string with a minimum of effort.

The complex syntax can be recognised by the curly braces surrounding the expression.

Update:

Please read on "Simple Syntax" and especially on "Complex Syntax" for this particular case.

print "<tr>
           <td>{$cards[$i]['card']}</td>
           <td><input class='amount' size='3' value='{$cards[$i]['pay']}'></td>
       </tr>";
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.