Jump to content

Krokodil

New Members
  • Posts

    5
  • Joined

  • Last visited

Krokodil's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. @Barand sorry but don't work. @kicken worked perfectly as i want thanks you very much !!!
  2. I will goo to sleep, i check code tomorrow; thanks for you're help. @benanamen : no it comes from an API and I don't store the information, it's a special project I just cache the data to avoid bothering the API
  3. There are entries in all languages, but I filter only English and French. I don't necessarily want the first entry, because sometimes it's not a trailer but an extrait of the movie, so that's why I look in the video name with preg_match. The data I give, are the same data with which I use my function.
  4. Sorry, i can't edit my post, but i have added my php code and here is the array code with 4 examples : stdClass Object ( [id] => 634649 [results] => Array ( [0] => stdClass Object ( [iso_639_1] => en [iso_3166_1] => US [name] => Peter Brings Villains To Happy's Condo [key] => Q8NbFwUGI38 [site] => YouTube [size] => 1080 [type] => Clip [official] => 1 [published_at] => 2022-08-09T00:00:06.000Z [id] => 62f1b9f3df857c007fb0d2e0 ) [1] => stdClass Object ( [iso_639_1] => en [iso_3166_1] => US [name] => The More Fun Stuff Version [key] => 6Bd2DZZi2eM [site] => YouTube [size] => 1080 [type] => Teaser [official] => 1 [published_at] => 2022-06-11T01:45:16.000Z [id] => 62a404ba85005d0052ca1b50 ) [2] => stdClass Object ( [iso_639_1] => en [iso_3166_1] => US [name] => The Condo Fight Scene [key] => vG7-hKnYcxQ [site] => YouTube [size] => 1080 [type] => Clip [official] => 1 [published_at] => 2022-05-16T21:00:21.000Z [id] => 628300e01495650066b593a5 ) [3] => stdClass Object ( [iso_639_1] => fr [iso_3166_1] => FR [name] => Spider-Man : No Way Home - Bande Annonce France [VF] [key] => o-qvJ2iUqvA [site] => YouTube [size] => 1080 [type] => Trailer [official] => 1 [published_at] => 2021-11-17T07:36:55.000Z [id] => 6196c4769603310062cf913a ) ) ) Edit : I have a solution, but I don't think it's really a good option, because doing 2 foreach for the same Array, it's not great function bandeAnnonce($videos) { foreach($videos->results as $key => $v) { if($v->iso_639_1 == 'fr') { if(preg_match('#bande|trailer#is', $v->name)) return (string) is_youtubeId($v->key); } } foreach($videos->results as $key => $v) { if(preg_match('#bande|trailer#is', $v->name)) { echo $v->key; return (string) is_youtubeId($v->key); } } return null; }
  5. Hello, In this array : https://pastebin.com/8nGbPx0P I want to check if the key "iso_639_1" is equal to "fr"and if yes, then I look for the value of the key "name" and if "iso_639_1" has no value "fr", then I want to go through the Array again looking for a key wtih valor "en", etc. But I don't know how to do it. If have try with if / else, but he stop when he find a good valor, he don't only check for FR valor, and if not exist, retry. This is my code : <?php function bandeAnnonce($videos) { foreach($videos->results as $key => $v) { if($v->iso_639_1 == 'fr') { if(preg_match('#bande|trailer#is', $v->name)) return (string) is_youtubeId($v->key); } else { if(preg_match('#bande|trailer#is', $v->name)) { echo $v->key; return (string) is_youtubeId($v->key); } } } return null; } Do you have an idea?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.