Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Filter multidimentional array 26 Oct 2012 09:32 #4750

  • dyvel
  • dyvel's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 200
  • Thank you received: 11
Hi

I know this should be simple, but I can't figure this one out correctly. I need to filter a multidimentional array on a date. Actually I need to filter on year only, but I thought I'd try with a date first.
Array
(
    [0] => Array
        (
            [0] => 2012-10-26
            [1] => 500
        )

    [1] => Array
        (
            [0] => 2012-10-25
            [1] => 500
        )

    [2] => Array
        (
            [0] => 2012-10-26
            [1] => 500
        )

)

Is the array example. I've tried
        foreach($revenueArray as $key => $row) {
		if( $row[0]=='2012-10-25' ):
			unset($revenueArray[$key]);
		endif;
	}

The strange part is, if I try to filter on the other value:
if( $row[1]==500 ):
			unset($revenueArray[$key]);
		endif;

then it works fine, so must be something about the date

But still no cigar :-)
If anybody know how, I'd appreciate the help.

Edit: strange part is, if I do a :
if (is_string($row[0])){ echo "yes it's a string"; }

Then it returns the echo, so why can't I compare a string to a string in [0] when I can in [1] ?

Thanks

Please Log in or Create an account to join the conversation.

Last edit: by dyvel.

Re: Filter multidimentional array 26 Oct 2012 11:49 #4751

  • dyvel
  • dyvel's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 200
  • Thank you received: 11
Found out why - I was using jdom to get the date value, but is was wrapping the value in a <span>. And that wasn't displaying when I printed the array. So no wonder why I couldn't compare the values. Got it working now by addressing the value directly (no dom)
The following user(s) said Thank You: JoomGuy

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.095 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started