Jump to content

Arrays


jstern

Recommended Posts

so I have an array (shipping) with a bunch of indexes. Such as name, address country etc.

I am able to debug and see whats in my array.

 

array

'firstName' => string 'Jordan' (length=6)

'lastName' => string 'Stern' (length=5)

'street1' => string '35 7th St Nw' (length=12)

'city' => string 'Bayamon' (length=7)

'province' => string 'choose' (length=6)

'province_hidden' => string '1' (length=1)

'country' => string 'choose' (length=6)

'country_hidden' => string '1' (length=1)

'zip' => string 'GY3 5HB' (length=7)

'phone' => string '4035291110' (length=10)

'business' => string 'Dev' (length=3)

'province_other' => string 'Puerto Rico' (length=11)

'country_other' => string 'Puerto Rico' (length=3)

 

I want to access 'country_other' so if a customer puts 'puetro rico' php can change it to usa.

 

I did this:

if (strtolower($this->post['shipping']['country_other']) == 'puerto rico') {

$this->post['shipping']['country_other'] = 'usa';

}

 

And it works when i debug:

 

array

'firstName' => string 'Jordan' (length=6)

'lastName' => string 'Stern' (length=5)

'street1' => string '35 7th St Nw' (length=12)

'city' => string 'Bayamon' (length=7)

'province' => string 'choose' (length=6)

'province_hidden' => string '1' (length=1)

'country' => string 'choose' (length=6)

'country_hidden' => string '1' (length=1)

'zip' => string 'GY3 5HB' (length=7)

'phone' => string '4035291110' (length=10)

'business' => string 'Dev' (length=3)

'province_other' => string 'Puerto Rico' (length=11)

'country_other' => string 'usa' (length=3)

 

But when I take my var_dump($this->post['shipping']) out, I get: "Undefined index: shipping in C:\dev\trunk\application\controllers\CheckoutController.php on line 972"

 

which is the same line as " if (strtolower($this->post['shipping']['country_other']) == 'puerto rico') {"

 

 

Any ideas?

Link to comment
Share on other sites

Undefined index:

 

If I remember from my debugging days that's caused by an variable being empty.. most often caused when you try to write out content from let say a $_POST or $_GET that is empty.

 

So are you vardumping something that is depending on something being sent through a form or by other means to the script?

 

Add the isset() function to only assign the value from $_POST or $_GET if a value was sent, that should fix your problem.

 

example:

 

// of course you need to apply this to your code with the correct indexes etc. 

if( isset($_POST['send']) {

// the code that uses the $_POST 

}

Link to comment
Share on other sites

Do keep in mind though -- this just hides the error, it doesn't change the fact that there is an error.

 

True, but what he was seeing was just notices, not true errors. You are right though, it should be coded so that there isn't anything to report in the first place

Link to comment
Share on other sites

If it were a personal site i was working on, maybe hiding the error would be acceptable. I am working full time for a company at the moment so Im sure i should be burying my bad code :P

 

I've got it sorted out, I actually changed the logic completely so I didnt have to start pulling and editing out of arrays.

 

Thanks!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...