Array help

I have this array below
$postDesc = array(
"client_id" => 900,
"date_from" => '2018-04-03',
"date_to" => '2018-04-03',
"property" => 12      
);

It works but I want to add multiple properties to return how is this done? When I add any it just returns the first one.

For example:
$propDesc = array(
"client_id" => 900,
"date_from" => '2018-04-03',
"date_to" => '2018-04-03',
"property_id" => 12, 14, 25      
);
ucohockeyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Try using an array for the multiple property_id values.

$propDesc = array(
"client_id" => 900,
"date_from" => '2018-04-03',
"date_to" => '2018-04-03',
"property_id" => array(12, 14, 25)
);
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ucohockeyAuthor Commented:
Thanks for the help but it jut returned error.
0
Jim RiddlesPrepress/OMS SpecialistCommented:
If I use Norie's example and use var_dump to dump the $propDesc variable, it looks like the following:
array(4) {
  ["client_id"] => int(900)
  ["date_from"] => string(10) "2018-04-03"
  ["date_to"] => string(10) "2018-04-03"
  ["property_id"] => array(3) {
    [0] => int(12)
    [1] => int(14)
    [2]=> int(25)
  }
}

Open in new window


There is no error.  What do you mean that it returned an error?  How did you try to access the property?
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Julian HansenCommented:
Thanks for the help but it jut returned error.
When suggestions from experts do not work or produce an error - it is useful to post the code that you used that generated the error along with the error. Simply saying that there was an error does not allow us to diagnose what the problem is.

The solution as provided is correct - therefore we can only assume that the error is due to
a) An error made in implementation
b) Some other aspect of the application that you have not revealed to us.
1
Olaf DoschkeSoftware DeveloperCommented:
The array design pattern is pretty straightforward key => value. And value can't be a list of values, unless you make it a value that is capable to store a list of values, as an array itself is.

But when you make use of that you get back whatever you store, so when you store an array(12,14,25) instead of a single value 12, you can't handle it as a single scalar value in any code reading this back.

If you can't change your code to handle that an array element might be an array itself, you could also change to store a single scalar value, a string '12,14,25':

$propDesc = array(
"client_id" => 900,
"date_from" => '2018-04-03',
"date_to" => '2018-04-03',
"property_id" => '12, 14, 25'
);

Open in new window


Strings always are a possibility, but also, in this case, you can't expect code previously expecting to get a single numeric value to now work on a list of values in a string. When you change the paradigm of something, that can't only mean the change of a single column in a table, an item of an array or such, some code will need to change, too.

What this helps with instead of an array is, you can store this in a table, it stays a "vanilla" associative array not nesting further finer structures, but if you had a table previously storing a single numeric id at that place, that will still need to change to allow storage of a string being a CSV. And a change of code handling this. And queries for property_id=12 will also not continue to work, even not when changing to property_id='12', now.

In the aspect of storing data in tables, this raises the need to alter your database in a way better than merely storing a CSV instead of a single id. What changed likely is a 1:1 relation becomes 1:n or a 1:n relation became n:m and that is a change requiring a little more work than that.

Bye, Olaf.
2
NorieAnalyst Assistant Commented:
Other experts indicated the solution I provided was correct.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
arrays

From novice to tech pro — start learning today.