My character moves right and left correctly, I want to know if it is possible to move character forward and backward to collect hearts (I know that in 2d no z axis I want to know if it is possible or not? )
There are definitley ways of accomplishing this without altering actual position of the character but instead making it appear that way.
For instance : You could try adding animations that show the character walking forward and backward (toward/away from screen) and scale his size to make it look like he is moving in the z axis.
Giving the illusion that there's a 3rd dimension has always been used on video games. It can be as simple or as complicated as you like, depending how you'd like the final result to look like.
In your case for example, you can move the character up/down using the Y-axis, to simulate that the character moves "back and forth". As long as the character interacts properly with the environment (in your case, picking up hearts when moving on the same plane as them) the illusion will not be noticed.
One example being Streets of Rage, which didn't even have an animation for moving up and down (it was just using the walk left/right one) and it made a very nice illusion. The character interacts perfectly with objects on the same plane as them, forcing the player to simulate this as 3D while they play.
You can of course change the scaling of the character as well, making them smaller as they move upwards, and bigger as they move downwards. This adds complexity, but gives a more realistic effect.
You can always add more complexity to add realism, but at the end of the day, it depends on the style you want your game to have. There is no wrong or right solution.