i want to get before come array string from array like :
i want this type
$array=array('ABC','BCD','DCB','KBC');
// now iwant get BCD using DCB
echo get_beforestring('DCB',$array);
// I want result BCD
I don’t have any solution for this, if you have any please let me tally. I am trying to solve it but am not able to do so. Because I am new to PHP coding, I don’t have an answer to this question, do you have an answer?
2
Answers
The following function will do what you’ve asked for and return false if the needle is not found in the array or has no preceding value:
If you also want it to work on arrays with non numeric indexes you could do:
Logic
Increment array key & compare the corresponding value with search item (for example ‘DCB’)
If both are matching, decrement array key & then return the corresponding value. STOP
Else if both does not match, go back to step 1
Implementation
Check following function that implements above logic inside a do-while loop