0

I don't know a ton of php, but my knowledge of javascript and ruby got me this far.. I've printed out an object (below) and I need to change a couple things about it before I display its contents to a user in an email.

The object is housed in a variable called: $item_meta

Here's the printout of the object in a REPL

I'm trying to remove the [Booking ID] and [Booking Date] properties and also change the wording of another key from [Monterey & Carmel Date (Must differ from Alcatraz date)] to: [Monterey & Carmel Date] and lastly (if possible) change the format of the previous field (monterey & carmel..) from 04/18/2016 to April 18th, 2016.

I've tried removing the first two properties using the unset() method, but wasn't able to access them properly from the object. That's my main issue, being able to traverse the object so I can remove or manipulate its contents.

Any help would be greatly appreciated, thanks! :)

nax3t
  • 117
  • 4
  • 4
  • 50
  • Why do you need to remove those properties? Can't you just not output them when you generate the email? – Don't Panic Apr 19 '16 at 17:54
  • Incidentally, to access object properties, you need to use object syntax (`$object->property`) rather than array syntax (`$array['index']`). – Don't Panic Apr 19 '16 at 17:58
  • Possible duplicate of [Is it possible to delete an object's property in PHP?](http://stackoverflow.com/questions/3600750/is-it-possible-to-delete-an-objects-property-in-php) – Don't Panic Apr 19 '16 at 18:00
  • I believe in order to "not output" them in the email I'd need to go further back to the class that instantiates the object to begin with. My limited knowledge of PHP and the codebase itself obviously being an obstacle there. But I think I found someone who can help me figure it out, so I'll post back later once I have a solution. Thanks! :) – nax3t Apr 20 '16 at 20:55

1 Answers1

0

Loop through the object.

For example

foreach ($item_meta as $value) {
    print_r($value);
}

Check the below link for more details.

How to loop through objects in php

Community
  • 1
  • 1
Sk_
  • 1,051
  • 8
  • 18
  • This is good, definitely one step closer to accessing the properties I need to change, however the print out is still a little cryptic, I can tell that each value from the item_meta is an array, but I'm still having trouble accessing them. For example, I would have thought I could access "Booking Data" like this: $value->{"Booking Data"}, but that doesn't seem to be working. In any event, I'm one step closer and should have some help from a friend this afternoon. Thanks for the tip! – nax3t Apr 20 '16 at 20:53