{"id":385,"date":"2013-08-01T12:11:06","date_gmt":"2013-08-01T10:11:06","guid":{"rendered":"http:\/\/vermiip.es\/blog\/?p=385"},"modified":"2013-08-01T12:13:30","modified_gmt":"2013-08-01T10:13:30","slug":"comprobar-si-un-valor-existe-en-un-array-php","status":"publish","type":"post","link":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/","title":{"rendered":"Comprobar si un valor existe en un array (PHP)"},"content":{"rendered":"<p>Si tenemos un array y queremos saber si hay un valor determinado dentro de \u00e9l sin tener que recorrerlo en PHP existe la funci\u00f3n in_array, que busca dentro del array y devuelve un TRUE o FALSE.<\/p>\n<p><strong>in_array(VALOR_A_BUSCAR, $NOMBRE_DEL_ARRAY)<\/strong><\/p>\n<p>Ejemplo:<\/p>\n<p>[PHP]<\/p>\n<p>\/\/Creamos el array colores<br \/>\n$colores =\u00a0array(\u00abrojo\u00bb,\u00a0\u00abazul\u00bb,\u00a0\u00abverde\u00bb,\u00a0\u00abamarillo\u00bb);<br \/>\nif\u00a0(in_array(\u00abverde\u00bb,\u00a0$colores))\u00a0{<br \/>\necho\u00a0\u00abEl color verde est\u00e1 en el array\u00bb;<br \/>\n}else{<br \/>\necho\u00a0\u00abLo siento, el color verde NO est\u00e1 en el array\u00bb;<br \/>\n}<\/p>\n<p>[\/PHP]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Si tenemos un array y queremos saber si hay un valor determinado dentro de \u00e9l sin tener que recorrerlo en PHP existe la funci\u00f3n in_array, que busca dentro del array y devuelve un TRUE o FALSE. in_array(VALOR_A_BUSCAR, $NOMBRE_DEL_ARRAY) Ejemplo: [PHP] \/\/Creamos el array colores $colores =\u00a0array(\u00abrojo\u00bb,\u00a0\u00abazul\u00bb,\u00a0\u00abverde\u00bb,\u00a0\u00abamarillo\u00bb); if\u00a0(in_array(\u00abverde\u00bb,\u00a0$colores))\u00a0{ echo\u00a0\u00abEl color verde est\u00e1 en el array\u00bb; }else{ [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[82,41],"tags":[68,69,20],"class_list":["post-385","post","type-post","status-publish","format-aside","hentry","category-php","category-programacion","tag-array","tag-in_array","tag-php","post_format-post-format-aside"],"_wp_attached_file":null,"_wp_attachment_metadata":null,"_wp_old_slug":null,"_aioseop_description":"Si tenemos un array y queremos saber si hay un valor determinado dentro de \u00e9l sin tener que recorrerlo en PHP existe la funci\u00f3n in_array, que busca dentro del array y devuelve un TRUE o FALSE.","_wp_attachment_image_alt":null,"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Comprobar si un valor existe en un array (PHP) - Ver mi IP<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Comprobar si un valor existe en un array (PHP) - Ver mi IP\" \/>\n<meta property=\"og:description\" content=\"Si tenemos un array y queremos saber si hay un valor determinado dentro de \u00e9l sin tener que recorrerlo en PHP existe la funci\u00f3n in_array, que busca dentro del array y devuelve un TRUE o FALSE. in_array(VALOR_A_BUSCAR, $NOMBRE_DEL_ARRAY) Ejemplo: [PHP] \/\/Creamos el array colores $colores =\u00a0array(\u00abrojo\u00bb,\u00a0\u00abazul\u00bb,\u00a0\u00abverde\u00bb,\u00a0\u00abamarillo\u00bb); if\u00a0(in_array(\u00abverde\u00bb,\u00a0$colores))\u00a0{ echo\u00a0\u00abEl color verde est\u00e1 en el array\u00bb; }else{ [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Ver mi IP\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-01T10:11:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-08-01T10:13:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vermiip.es\/blog\/wp-content\/uploads\/2023\/10\/cropped-logo-vermiip-naranja.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Xose\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Xose\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/\"},\"author\":{\"name\":\"Xose\",\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#\\\/schema\\\/person\\\/a51689537a81b5c5c66031151b0f73a1\"},\"headline\":\"Comprobar si un valor existe en un array (PHP)\",\"datePublished\":\"2013-08-01T10:11:06+00:00\",\"dateModified\":\"2013-08-01T10:13:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/\"},\"wordCount\":93,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#organization\"},\"keywords\":[\"array\",\"in_array\",\"php\"],\"articleSection\":[\"php\",\"Programaci\u00f3n\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/\",\"url\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/\",\"name\":\"Comprobar si un valor existe en un array (PHP) - Ver mi IP\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#website\"},\"datePublished\":\"2013-08-01T10:11:06+00:00\",\"dateModified\":\"2013-08-01T10:13:30+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/comprobar-si-un-valor-existe-en-un-array-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Portada\",\"item\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Comprobar si un valor existe en un array (PHP)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/\",\"name\":\"Cual es mi ip - Internet y otras locuras\",\"description\":\"Internet y otras locuras\",\"publisher\":{\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#organization\"},\"alternateName\":\"Cual es mi IP\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#organization\",\"name\":\"Ver mi IP\",\"alternateName\":\"vermiip\",\"url\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/cropped-logo-vermiip-naranja.png\",\"contentUrl\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/10\\\/cropped-logo-vermiip-naranja.png\",\"width\":512,\"height\":512,\"caption\":\"Ver mi IP\"},\"image\":{\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vermiip.es\\\/blog\\\/#\\\/schema\\\/person\\\/a51689537a81b5c5c66031151b0f73a1\",\"name\":\"Xose\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0d9f11f6facf8d2f6109858fbb8fd2e7da1e2c41983bc8d9269bba5fb12b3718?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0d9f11f6facf8d2f6109858fbb8fd2e7da1e2c41983bc8d9269bba5fb12b3718?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/0d9f11f6facf8d2f6109858fbb8fd2e7da1e2c41983bc8d9269bba5fb12b3718?s=96&d=mm&r=g\",\"caption\":\"Xose\"},\"sameAs\":[\"http:\\\/\\\/www.enfocado.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Comprobar si un valor existe en un array (PHP) - Ver mi IP","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/","og_locale":"es_ES","og_type":"article","og_title":"Comprobar si un valor existe en un array (PHP) - Ver mi IP","og_description":"Si tenemos un array y queremos saber si hay un valor determinado dentro de \u00e9l sin tener que recorrerlo en PHP existe la funci\u00f3n in_array, que busca dentro del array y devuelve un TRUE o FALSE. in_array(VALOR_A_BUSCAR, $NOMBRE_DEL_ARRAY) Ejemplo: [PHP] \/\/Creamos el array colores $colores =\u00a0array(\u00abrojo\u00bb,\u00a0\u00abazul\u00bb,\u00a0\u00abverde\u00bb,\u00a0\u00abamarillo\u00bb); if\u00a0(in_array(\u00abverde\u00bb,\u00a0$colores))\u00a0{ echo\u00a0\u00abEl color verde est\u00e1 en el array\u00bb; }else{ [&hellip;]","og_url":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/","og_site_name":"Ver mi IP","article_published_time":"2013-08-01T10:11:06+00:00","article_modified_time":"2013-08-01T10:13:30+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/vermiip.es\/blog\/wp-content\/uploads\/2023\/10\/cropped-logo-vermiip-naranja.png","type":"image\/png"}],"author":"Xose","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Xose"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/#article","isPartOf":{"@id":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/"},"author":{"name":"Xose","@id":"https:\/\/vermiip.es\/blog\/#\/schema\/person\/a51689537a81b5c5c66031151b0f73a1"},"headline":"Comprobar si un valor existe en un array (PHP)","datePublished":"2013-08-01T10:11:06+00:00","dateModified":"2013-08-01T10:13:30+00:00","mainEntityOfPage":{"@id":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/"},"wordCount":93,"commentCount":6,"publisher":{"@id":"https:\/\/vermiip.es\/blog\/#organization"},"keywords":["array","in_array","php"],"articleSection":["php","Programaci\u00f3n"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/","url":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/","name":"Comprobar si un valor existe en un array (PHP) - Ver mi IP","isPartOf":{"@id":"https:\/\/vermiip.es\/blog\/#website"},"datePublished":"2013-08-01T10:11:06+00:00","dateModified":"2013-08-01T10:13:30+00:00","breadcrumb":{"@id":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vermiip.es\/blog\/comprobar-si-un-valor-existe-en-un-array-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Portada","item":"https:\/\/vermiip.es\/blog\/"},{"@type":"ListItem","position":2,"name":"Comprobar si un valor existe en un array (PHP)"}]},{"@type":"WebSite","@id":"https:\/\/vermiip.es\/blog\/#website","url":"https:\/\/vermiip.es\/blog\/","name":"Cual es mi ip - Internet y otras locuras","description":"Internet y otras locuras","publisher":{"@id":"https:\/\/vermiip.es\/blog\/#organization"},"alternateName":"Cual es mi IP","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vermiip.es\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/vermiip.es\/blog\/#organization","name":"Ver mi IP","alternateName":"vermiip","url":"https:\/\/vermiip.es\/blog\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/vermiip.es\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/vermiip.es\/blog\/wp-content\/uploads\/2023\/10\/cropped-logo-vermiip-naranja.png","contentUrl":"https:\/\/vermiip.es\/blog\/wp-content\/uploads\/2023\/10\/cropped-logo-vermiip-naranja.png","width":512,"height":512,"caption":"Ver mi IP"},"image":{"@id":"https:\/\/vermiip.es\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/vermiip.es\/blog\/#\/schema\/person\/a51689537a81b5c5c66031151b0f73a1","name":"Xose","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/secure.gravatar.com\/avatar\/0d9f11f6facf8d2f6109858fbb8fd2e7da1e2c41983bc8d9269bba5fb12b3718?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/0d9f11f6facf8d2f6109858fbb8fd2e7da1e2c41983bc8d9269bba5fb12b3718?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0d9f11f6facf8d2f6109858fbb8fd2e7da1e2c41983bc8d9269bba5fb12b3718?s=96&d=mm&r=g","caption":"Xose"},"sameAs":["http:\/\/www.enfocado.com"]}]}},"_links":{"self":[{"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/posts\/385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/comments?post=385"}],"version-history":[{"count":4,"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":389,"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/posts\/385\/revisions\/389"}],"wp:attachment":[{"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/media?parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/categories?post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vermiip.es\/blog\/wp-json\/wp\/v2\/tags?post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}