1

I would take words in several tables to get a sentence.

My first array : $ARRAYTREE

[Choose] => RED
[a] => BLUE
[job] => ORANGE
[you] => YELLOW
[love] => GREEN
[,] => PURPLE
[and] => CYAN
[you] => YELLOW
 [will] => BLACK
 [never] => GREEN
 [have] => BLACK
 [to] => CYAN
 [work] => ORANGE
 [a] => BLUE
 [day] => YELLOW
 [in] => CYAN
 [your] => YELLOW
 [life] => ORANGE
 [.] => PURPLE

Values of change: PURPLE, BLACK

I managed to get the words from my first array ($ARRAYTREE), getting the following sentence:

 "Choose a job you love "

What I’m looking for some time, it is from this end of sentence, to look for the presence of two values PURPLE and CYAN that contact to realize a transition. When these two values are found, it is necessary to take all the keys of the array until time we arrive at a new value of change (PURPLE or BLACK). With array 2 ($ARRAYTREE2), I will get the following words :

", go with all your heart "

My second array : $ARRAYTREE2

 [Wheresoever] => GREEN
 [you] => YELLOW
 [go] => BLACK
 [,] => PURPLE
 [go] => CYAN
 [with] => GREEN
 [all] => CYAN
 [your] => YELLOW
 [heart] => ORANGE
 [.] => PURPLE

Giving in the end this character string:

"Choose a job you love , go with all your heart "

I tried with the method of array_search and array_slice but without result ...

Thanks to the person who deigns to answer me...

1 Answer 1

2

Loop through the array until [key] => [purple], when it reaches the condition, start copying the next characters until the key is again equal to purple at the end.

You can do this in foreach loops. And also by using a flag condition in the loop going over your array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.