1

I created an array below:

$email[] = $post[0];

$email[].= $post[2];

The result is:

$email = Array ( [JESSICA] => [email protected] ) 

I then pass it to a class constructor as so:

$email_user = new Email($id,$email,$subject,$heading,$messages,$keys);

The class looks like this:

class Email extends Users { 

protected $id;
public $strings;
public $user_email;
public $subject;
public $heading;
public $messages;
public $keys;

public function __construct($id,$user_email,$subject,$heading,$messages,$keys) {

parent::__construct($id);
$this->user_email = $user_email;
$this->subject = $subject;
$this->heading = $heading;
$this->messages = $messages;
$this->keys = $keys;

If I test to see if $this->user_email is an array using:

if(is_array($this->user_email)) {
   echo "TRUE";
}

it returns false. How come?

* I found the issue, a conflict with variables both named $email. Thanks for the help.

8
  • 1
    $email[].=? You can do that? Commented May 10, 2012 at 14:44
  • @Rocket - I suspect you can, but it'd be the equivalent of $email[] = NULL . ? Commented May 10, 2012 at 14:45
  • @MarkBaker: I tested it and the . doesn't do anything. It's the same as $email[] =. Commented May 10, 2012 at 14:46
  • Yes, the dot notation doees nothing. Commented May 10, 2012 at 14:48
  • 2
    @stevenpepe, are you sure that the result in the $email variable is the array you describe? You're not setting the [JESSICA] element anywhere in the example you give. Commented May 10, 2012 at 14:49

2 Answers 2

2

Beware that the use of the .= operator is generally used for concatinating two strings.

by saying $email[] = somevalue, you're essentially pushing the value arbitrarily into the array, which is totally good enough for what you're doing. You end up with:

$email[] = $post[0];
$email[] = $post[2];
Sign up to request clarification or add additional context in comments.

Comments

0

try:

public $user_email = array();

Remove the concatenation: $email[].= $post[2]; $email[] = $post[2]; is fine.

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.