Hey guys I'm trying to see where my pairs of keys stop, I have arrays built like this
EDIT People are getting really confused so I'm using a real array instead of an example
array (
'key' => '',
'po' => '',
'label' => '',
'report_key' => '',
'shipper' => '',
'status' => '',
'location' => '',
'inspector' => '',
'commodity' => '',
'brand' => '',
'case_count' => '',
'variety' => '',
'style' => '',
'grower_lot' => '',
'pack_date' => '',
// grouping 4 items
'berry_size1' => '',
'berry_size2' => '',
'berry_size3' => '',
'berry_size4' => '',
// grouping 3 items
'bunch_color1' => '',
'bunch_color2' => '',
'bunch_color3' => '',
// grouping 2 items
'color1' => '',
'color2' => '',
// grouping 3 items
'stem1' => '',
'stem2' => '',
'stem3' => '',
// grouping 2 items
'shatter1' => '',
'shatter2' => '',
// grouping 2 items
'splits1' => '',
'splits2' => '',
// grouping 2 items
'wet_sticky1' => '',
'wet_sticky2' => '',
'overall_quality' => '',
// grouping 2 items
'sugar_brix1' => '',
'sugar_brix2' => '',
'rating' => '',
'comments' => '',
)
I came up with some stupid way that really doesn't work to try and sort things out, its extremely backwards, honestly I'm pretty embarrassed by my attempt.
foreach($obj as $key=>$val) {
if(strpos( preg_replace('/[^a-z]/i', '', $key),
preg_replace('/[^a-z]/i', '', $all_keys[$key+$b+1])
) !== false) { echo "<p>$key</p>"; // items 1-3 will show
} elseif(strpos(preg_replace('/[^a-z]/i', '', $key),
preg_replace('/[^a-z]/i', '', $all_keys[$key+$b-1])
) !== false) { echo "<p>$key</p>"; // show last item
} else {
$in.='<aside class="left">';
$in .= "<label for='$key'>". ucwords(strtolower(str_replace('_',' ',$key))) ."</label><br/>";
$in .= ($key=='key') ? "<input type='text' value='". $objLastId ."' id='$key' class='disabled' disabled='disabled'>" : "<input type='text' value='' name='$key' id='$key'>";
$in.='</aside>';
$b++;
}
}
Anyway what I'm really trying to achieve is something like this, could someone steer me in the right direction please?
<style>
.row2 input {width: 50px !important;}
.row3 input {width: 27px !important;}
.row4 input {width: 15px !important;}
</style>
// stem was a 2 item group, so should have the row4 class
// and should have the second item appended by a
// all be inside the same grouping, like below ...
<aside class="left row2">
<label for="color1">Color</label>
<br/><input type="text" value="" name="color1" id="color1">
<input type="text" value="" name="color2" id="color2">
</aside>
// stem was a 3 item group, so should have the row4 class
// and should have items 2-3 appended by a all be inside
// the same grouping, like below ...
<aside class="left row3">
<label for="stem1">Stem</label>
<br><input type="text" id="stem1" name="stem1" value="">
<input type="text" id="stem2" name="stem2" value="">
<input type="text" id="stem3" name="stem3" value="">
</aside>
// berry_size was a 4 item group, so should have the row4 class
// and should have items 2-4 appended by a all be inside
// the same grouping, like below ...
<aside class="left row4">
<label for="berry_size1">Berry Size</label>
<br/><input type="text" id="berry_size1" name="berry_size1" value="">
<input type="text" id="berry_size2" name="berry_size2" value="">
<input type="text" id="berry_size3" name="berry_size3" value="">
<input type="text" id="berry_size4" name="berry_size4" value="">
</aside>
... or ...
// this is a single, so no extra class and ....
<aside class="left">
<label for="other_item">Other Item</label>
<br/><input type="text" id="other_item" name="other_item" value="">
</aside>
What I see this really boiling down to is reading the next array keys name (I stripped the name and used the integer in my version), atleast I think that's the right way to do it?