Compare values of a multidimensional array in php

Asked

Viewed 179 times

0

I have the following array I need to generate confrontations between them aletorios and the teams of the same array Ex. Santos and São Paulo cannot face each other!!

array(5) {
  [1]=>
  array(2) {
    [0]=>
    string(6) "Santos"
    [1]=>
    string(8) "São Paulo"
  }
  [2]=>
  array(1) {
    [0]=>
    string(7) "Flamengo"
  }
  [3]=>
  array(1) {
    [0]=>
    string(6) "Gremio"
  }
  [4]=>
  array(1) {
    [0]=>
    string(8) "Cruzeiro"
  }
  [5]=>
  array(1) {
    [0]=>
    string(5) "Sport"
  }
}

My end result will be something like:

Flemish x Santos
São Paulo* x *Gremio
Sport x Cruising

Never Santos x São Paulo

I couldn’t think of a way to compare array values dynamically since I can have more teams registered!!

  • Your example got confused. Post what you have and how you want, to make it clear.

  • So I tried to use foreach to see if the teams are in the same array, but I couldn’t!! I need to create a confrontation between it being the teams that are in the same array ex. São Paulo and Santos could not face each other. I do not know if there is a function that already scan the array and make this comparison!!

  • I understand, I’ve tried several ways and it didn’t work!! but I will copy here the code of the attempts. Meanwhile the end result would have to be something like: Sport x Cruzeiro Gremio x São Paulo Santos x Flamengo Where such confrontations should be random and São Paulo e Santos cannot face each other!!

  • Will all be account all? apart from those in the same array, would that be it. You can use in_array to compare whether the team drawn is in the same array or has already been generating a game for it.

  • Improved with editing, but still can not understand this your array. Pq has 2 items in the first, and the rest is all separate team? It would be nice to explain it better. Note that as much as the community wants to help you, without knowing more details it is impossible. You know what you’re trying to do, but we’ll only know what’s in the question to be read.

  • I get it, the first one has two items to be teams from the same state so they can’t face each other in the first round!!

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.