Solved

Php Array Diff

Posted on 2016-11-01
3
38 Views
Last Modified: 2016-11-01
Hi,

I have 2 arrays

$dates
Array
(
    [0] => 2016-11-01
    [1] => 2016-11-08
    [2] => 2016-11-15
    [3] => 2016-11-22
    [4] => 2016-11-29
)

$holidays
Array
(
    [0] => 2016-11-07
    [1] => 2016-11-08
    [2] => 2016-11-09
    [3] => 2016-11-10
    [4] => 2016-11-11
)

$totals =  array_diff($dates, $termtimedates) . '<br><br>';
			
			echo $totals . '<br><br>';

Open in new window


All I get back is word "Array"

Any ideas thanks
0
Comment
Question by:pc-buddy
  • 2
3 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41868765
When your script uses echo to print out an array, PHP unhelpfully substitutes the value "Array."  Try using print_r($totals) instead.
0
 

Author Closing Comment

by:pc-buddy
ID: 41868772
Yeah just figured that out haha, thanks
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41868797
This happens any time PHP does type-coercion from Array to String (not just in echo).  It's a terrible design flaw, but it's too late to fix it now that it's been baked into the language.  A more appropriate approach would be to trigger a warning!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now