Search an array

Hello!

I have an array with several values but some I don’t necessarily have them complete as some are URLs so I may have an array like this

Array[0] ‘{’
Array[1] ‘plugin’
Array[2] ‘random_word’
Array[3] ‘http://somewebsite.com/somefolder/somefile.php
Array[4] ‘300::300’
Array[5] ‘}’

Those values are passed to the script and the only things I am sure are

Array[0] ‘{’ //will always be this
Array[1] ‘plugin’ //will always be this
Array[2] ‘random_word’ //this will always be a word from a list
Array[3] ‘http://somewebsite.com/somefolder/somefile.php
Array[4] ‘300::300’
Array[5] ‘}’ //this will always be a bracket but it will not necessarily be Array[5] it will be a closing bracket on the last item of the array

I am trying to find a way to find an item knowing the first part of it, like Array[3] in this case is an URL but I don’t know the index of it can I find it by doing a search for “http://”?

What are you trying to accomplish?

And why are you using numeric keys when associative labels would be cleaner and easier to understand


array(
  'plugin' => 'plug in value',
  'random_word' => 'random word value',
  'url' => 'http://url.com/folder',
  'dimensions' => array (
    'width' => 300,
    'height' => 300,
  )
)

I see no rational reason to have braces be part of your array contents.

the thing is I am getting a string in the form of $plugin=‘{|plugin|rendom_word|300|http://someurl.com/|value,value,value|}’
and that might vary but the brackets and | are there always so I am using explode(‘|’, $plugin) that is why the brackets are there, basically I am expecting some values like an URL a list of comma separated values, a width and height value in the form of either 300 or 300::300 and some other values but I might not get them in a specific order that is why I don’t know the index of each value

And where are you getting this string if I may ask?

a user inputs the string in that form

okay, a different question, how can I do a search on an array using a regular expression?

Why? Why not give them multiple input fields for each datum you are gathering?

because I cant change the structure that is already there, the only way for me is this, there is a text where they can enter the string in that form, I search for matches explode the string and that is what I have, but thank you I figured out how to do it

Why can’t you?

Asking users to enter something in code isn’t very efficient. And the chances of them getting it wrong are extremely high. Most people don’t even know where the | character is on the keyboard.

We are a team of 5 people and I am referring to us as the users, we all know where the | sign is

I am making a plugin for joomla so anyone trying to use it will know that in advance also I am sorry but I did not come in here for a debate on this I only wanted some input because I was not able to figure it out myself, you asking me all those unrelated questions do not help me if you had an answer for my real question then it would be great to hear it instead of the rest, as of now I am using preg_grep with a regular expression and it is working.

My plugin is already working however the users have to enter the properties in certain order by doing this I will enable the users to enter the properties in any order, we are just trying to make our work easier, once this is done it will be much easier for my team to do what we are trying to and we, (the users) know where the | sign is I am sorry if this sounds rude but I was trying to get an answer but instead I got a whole bunch of questions

A lot of people come in here asking questions. About half the time a little searching into the reason they are asking the questions reveals they are proceeding from a flawed premise - and the question they are asking isn’t the one they should be asking. For that reason I took the time to ask questions of my own in an attempt to help.

Having worked with Joomla extensively, I know there are better ways to go about what you are doing and now that you mention that CMS by name I’m pretty sure of what you are up to. However, I will not divulge them to you because of your rudeness. Good day.

Michael, I am sorry if I was rude but I was a bit annoyed for all the questioning.

The reason I told you that is because for me, when someone is asking me a question, I think it is valid to ask for certain clarifications, however I do think that there could also be, aside from all the clarification, the answer or an attempt to answer the question in hand.

That is just my point of view and yes I might be wrong in the way I am doing things and I am sure there are better ways, I just don’t know them; I will never do if I don’t try and then don’t ask when I’m stuck, and I do think that also for you there are better ways of doing things.

I hope you don’t take this the wrong way and I do appreciate you trying to help me.