Saltar al contenido

Imprimir array de forma legible con php (3 métodos)

imprimir-array-legible-en-php

En ocasiones mientras estamos programando necesitamos mostrar el contenido de un arreglo de manera legible y clara , es por eso que hoy te enseñare 3 formas de imprimir un array de forma legible en php.

Haremos uso de 3 funciones que sirven para mostrar información estructurada de una variable.

En este post no explicare detalladamente como crear un arreglo, si quieres saber mas detalles sobre los arreglos en php visita este post.

Crearemos nuestro arreglo y almacenaremos datos en el de la siguiente manera:

Imprimir arreglo legible y claro con print_r() en php

Para imprimir un array legible y claro en php utilizaremos la función print_r() y las etiquetas <pre> de HTML que sirven para presentar texto preformateado.

Solo basta con llamar la funcion print_r($dias); envuelta en etiquetas <pre> y obtendremos lo siguiente:

El resultado es una manera bastante legible de ver el contenido del arreglo.

Mostrar arreglo legible y claro con var_dump() en php

La función var_dump() envuelta en las etiquetas HTML <pre> imprime el contenido del arreglo de manera legible.

EL código es similar al anterior solo cambia la forma en la que imprimimos el arreglo ya que ahora lo hacemos con la función var_dump , el resultado se ve asi:

El resultado es un poco mas detallado que la función anterior ya que aquí se especifica el tipo de dato que almacena el array.

Mostrar array legible y claro con var_export() en php

Por ultimo te mostrare como imprimir el contenido de un array de forma legible con la funcion var_export()

Las tres funciones imprimen el contenido del array de una forma clara pero un poco diferente una de la otra, el resultado de la función var_export() luce así:

A mi parecer este método es el mas eficiente en cuanto a imprimir un array de forma clara y legible pero tu puedes utilizar la que gustes, las tres son muy efectivas.

Gracias por leer este artículo y esperamos que encuentres útil esta información. Si tienes preguntas o sugerencias adicionales, no dudes en comentar. ¡Nos encantará escuchar de ti!
Hasta la próxima oportunidad, ¡nos despedimos!

Puedes apoyar el blog de diferentes maneras:
Suscribiéndote al Blog.
Apoyando mi trabajo..
Invitándome un café.☕
Seguirme en redes sociales.
o compartir mi contenido en redes sociales. ⬇️

4 comentarios en «Imprimir array de forma legible con php (3 métodos)»

  1. Hello Codigoroot Owner

    My name’s Eric and I’m betting you’d like your website Codigoroot to generate more leads.

    Here’s how:

    Web Visitors Into Leads is a software widget that works on your site, ready to capture any visitor’s Name, Email address, and Phone Number. It signals you as soon as they say they’re interested – so that you can talk to that lead while they’re still there at Codigoroot.

    https://resultleadgeneration.com for a live demo now.

    And now that you’ve got their phone number, our new SMS Text With Lead feature enables you to start a text (SMS) conversation – answer questions, provide more info, and close a deal that way.

    If they don’t take you up on your offer then, just follow up with text messages for new offers, content links, even just «how are you doing?» notes to build a relationship.

    https://resultleadgeneration.com to discover what Web Visitors Into Leads can do for your business.

    The difference between contacting someone within 5 minutes versus a half-hour means you could be converting up to 100X more leads today!

    Try Web Visitors Into Leads and get more leads now.

    Eric

    PS: Studies show that 70% of a site’s visitors disappear and are gone forever after just a moment. Don’t keep losing them.
    Web Visitors Into Leads offers a complimentary 14-day trial – and it even includes International Long Distance Calling.
    You have customers waiting to talk with you right now… don’t keep them waiting.
    https://resultleadgeneration.com to try Web Visitors Into Leads now.

    We are strongly committed to protecting your privacy and providing a safe & high-quality online experience for our visitors. We understand that you care about how the information you provide to us is used and shared. We have developed a Privacy Policy to inform you of our policies about the collection, use, and disclosure of information we receive from users of our website. We operate the Website.

    Our Privacy Policy, along with our Terms & Conditions, governs your use of this site. By using the website, or by accepting the Terms of Use (via opt-in, checkbox, pop-up, or clicking an email link confirming the same), you agree to be bound by our Terms & Conditions and our Privacy Policy.

    If you have provided any voluntarily given information, you may review and make changes to it via instructions found on the Website. To manage your receipt of marketing and non-transactional communications, you may unsubscribe by clicking the unsubscribe link located on the bottom of any marketing email. Emails related to the purchase or delivery of orders are provided automatically – Customers are not able to opt out of transactional emails. We will try to accommodate any requests related to the management of personal information in a timely manner. However, it may not always be possible to fully remove or modify information in our databases if we have a valid reason to keep it for certain timeframes. If you have any questions, simply see our website to view our official policies.

    Our primary goal is to help you with lead generation. These emails are meant to give you advice on that topic, or to promote products that will help you have the kind of business films are written about.

    If you’d like to Want to receive fewer emails, or none whatsoever? Update your email preferences by visiting https://resultleadgeneration.com/unsubscribe.aspx?d=codigoroot.net

  2. Hello Codigoroot Owner,

    My name’s Eric and for just a second, imagine this…

    – Someone does a search and winds up at Codigoroot.
    – They hang out for a minute to check it out. I’m interested… but… maybe…
    – And then they hit the back button and check out the other search results instead.
    – Bottom line – you got an eyeball, but nothing else to show for it.
    – There they go.

    This isn’t really your fault – it happens a LOT – studies show 7 out of 10 visitors to any site disappear without leaving a trace.

    But you CAN fix that.

    Web Visitors Into Leads is a software widget that works on your site, ready to capture any visitor’s Name, Email address, and Phone Number. It lets you know right then and there – enabling you to call that lead while they’re literally looking over your site.

    https://resultleadgeneration.com to try out a Live Demo with Web Visitors Into Leads now to see exactly how it works.

    Time is money when it comes to connecting with leads – the difference between contacting someone within 5 minutes versus 30 minutes later can be huge – like 100 times better!

    Plus, now that you have their phone number, with our new SMS Text With Lead feature, you can automatically start a text (SMS) conversation… so even if you don’t close a deal then, you can follow up with text messages for new offers, content links, even just how you doing? notes to build a relationship.

    Strong stuff.

    https://resultleadgeneration.com to discover what Web Visitors Into Leads can do for your business.

    You could be converting up to 100X more leads today!

    Eric

    PS: Studies show that 70% of a site’s visitors disappear and are gone forever after just a moment. Don’t keep losing them.
    Web Visitors Into Leads offers a complimentary 14-day trial – and it even includes International Long Distance Calling.
    You have customers waiting to talk with you right now… don’t keep them waiting.
    https://resultleadgeneration.com to try Web Visitors Into Leads now.

    We are strongly committed to protecting your privacy and providing a safe & high-quality online experience for our visitors. We understand that you care about how the information you provide to us is used and shared. We have developed a Privacy Policy to inform you of our policies about the collection, use, and disclosure of information we receive from users of our website. We operate the Website.

    Our Privacy Policy, along with our Terms & Conditions, governs your use of this site. By using the website, or by accepting the Terms of Use (via opt-in, checkbox, pop-up, or clicking an email link confirming the same), you agree to be bound by our Terms & Conditions and our Privacy Policy.

    If you have provided any voluntarily given information, you may review and make changes to it via instructions found on the Website. To manage your receipt of marketing and non-transactional communications, you may Want to receive fewer emails, or none whatsoever? Update your email preferences.

    Emails related to orders are provided automatically – customers are not able to opt out of these. We will try to address any requests related to the management of personal information in a timely manner. However, it may not always be possible to fully remove or modify information in our databases if we have a valid reason to keep it for certain timeframes. If you have any questions, simply see our website to view our official policies.

    Our primary goal is to help you with lead generation. These emails are meant to give you advice on that topic, or to promote products that will help you have the kind of business films are written about.

    If you’d like to Want to receive fewer emails, or none whatsoever? Update your email preferences by visiting https://resultleadgeneration.com/unsubscribe.aspx?d=codigoroot.net

  3. Hello Codigoroot Owner,

    My name’s Eric and for just a second, imagine this…

    – Someone does a search and winds up at Codigoroot.
    – They hang out for a minute to check it out. I’m interested… but… maybe…
    – And then they hit the back button and check out the other search results instead.
    – Bottom line – you got an eyeball, but nothing else to show for it.
    – There they go.

    This isn’t really your fault – it happens a LOT – studies show 7 out of 10 visitors to any site disappear without leaving a trace.

    But you CAN fix that.

    Web Visitors Into Leads is a software widget that works on your site, ready to capture any visitor’s Name, Email address, and Phone Number. It lets you know right then and there – enabling you to call that lead while they’re literally looking over your site.

    https://resultleadgeneration.com to try out a Live Demo with Web Visitors Into Leads now to see exactly how it works.

    Time is money when it comes to connecting with leads – the difference between contacting someone within 5 minutes versus 30 minutes later can be huge – like 100 times better!

    Plus, now that you have their phone number, with our new SMS Text With Lead feature, you can automatically start a text (SMS) conversation… so even if you don’t close a deal then, you can follow up with text messages for new offers, content links, even just how you doing? notes to build a relationship.

    Strong stuff.

    https://resultleadgeneration.com to discover what Web Visitors Into Leads can do for your business.

    You could be converting up to 100X more leads today!

    Eric

    PS: Studies show that 70% of a site’s visitors disappear and are gone forever after just a moment. Don’t keep losing them.
    Web Visitors Into Leads offers a complimentary 14-day trial – and it even includes International Long Distance Calling.
    You have customers waiting to talk with you right now… don’t keep them waiting.
    https://resultleadgeneration.com to try Web Visitors Into Leads now.

    We are strongly committed to protecting your privacy and providing a safe & high-quality online experience for our visitors. We understand that you care about how the information you provide to us is used and shared. We have developed a Privacy Policy to inform you of our policies about the collection, use, and disclosure of information we receive from users of our website. We operate the Website.

    Our Privacy Policy, along with our Terms & Conditions, governs your use of this site. By using the website, or by accepting the Terms of Use (via opt-in, checkbox, pop-up, or clicking an email link confirming the same), you agree to be bound by our Terms & Conditions and our Privacy Policy.

    If you have provided any voluntarily given information, you may review and make changes to it via instructions found on the Website. To manage your receipt of marketing and non-transactional communications, you may Want to receive fewer emails, or none whatsoever? Update your email preferences.

    Emails related to orders are provided automatically – customers are not able to opt out of these. We will try to address any requests related to the management of personal information in a timely manner. However, it may not always be possible to fully remove or modify information in our databases if we have a valid reason to keep it for certain timeframes. If you have any questions, simply see our website to view our official policies.

    Our primary goal is to help you with lead generation. These emails are meant to give you advice on that topic, or to promote products that will help you have the kind of business films are written about.

    If you’d like to Want to receive fewer emails, or none whatsoever? Update your email preferences by visiting https://resultleadgeneration.com/unsubscribe.aspx?d=codigoroot.net

  4. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make
    your point. You obviously know what youre talking about,
    why throw away your intelligence on just posting videos to your weblog when you could be giving us something informative to read?

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *