I am trying to find a better way to switch to replacing strings with multiple sorts.
I have a sentence that is inserted by the user, I have an array, which of all the missing words in this sentence and their possible corrections.
$sentence = 'i want to recovary my vehical from the cabs';
I want to display the following:
- I want to restore my car from the cab.
- I want to get my car back from the cab.
- I want to review my car from the cab.
Code so far:
$element = array( "vehical" => array('vehicle'), "recovary" => array('recovery', 'recover', 'revary') ); $sentence = 'i want to recovary my vehical from the cabs'; foreach($element as $i => $val){ echo $i; }
EDIT: expanded another scenario:
What happens if there were several options in the top array.
"vehical" => array('vehicle', 'vehiclesy', 'whatever'), "recovary" => array('recovery', 'recover', 'revary')
- I want to restore my car from the cab.
- I want to restore my car from the cab.
- I want to restore everything from the cockpit
- I want to get my car back from the cab.
- I want to restore my car from the cab.
- I want to regain everything from the cockpit
- I want to review my car from the cab.
- I want to review my vehicles from cabs.
- I want to respond to everything from the cockpit
arrays loops php
Sophie rhodes
source share