We help IT Professionals succeed at work.
Get Started

Searching keys of multi-dimensional array and returning true, then getting values without looping.

t3chguy asked
Last Modified: 2015-03-03
I have a multi-dimensional array that is created when a user dynamically adds options to a form.

When the form is posted, I have been tasked with matching their dynamic inputs with static options on a PDF.

I'm not sure how to go about tackling this one.

My array looks like this:

    [1] => Array
            ['type_of_work'] => Storm Lift Stations
            ['hours'] => 8
            ['qty'] => 1

    [2] => Array
            ['type_of_work'] => Hydrant Install/Adjust
            ['hours'] => 5
            ['qty'] => 3


Open in new window

I now have a static HTML table that will be converted to a PDF that appears like this:

$html .= '<tr>
			<td>Storm Lift Stations</td>
			<td>Hours Here</td>
			<td>Cost Here</td>
$html .= '<tr>
			<td>Water Main Construction</td>

Open in new window

If the term "Storm Lift Stations" appears in that array, I need to get the cost and the number of hours stored in the array and place them in the appropriate columns. Since "Water Main Construction" was not in the array posted, nothing would get filled in here.

I tried making a function that would return true if a specific array key was found, but nothing gets printed..and even if it did, I'm still left in the dark matching the hours and quantity of this array.

I realize that this would be better off it built the HTML tables dynamically based on what the user selects from the form, but my client is asking me manipulate their inputs so it matches a PDF form I was given.

I appreciate any guidance!  Thank you.
Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 2 Answers and 12 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE