/ / Using the explode PHP function

Using the explode PHP function

The semantics of the development of programming languages ​​andspheres of their applications quickly took the right positions. Of course, mathematical calculations of the trajectories of planets and the movement of exchange rates in the markets still excite society, but also the lines of symbols occupy a worthy place there.

explode php

An important point: from the strict typing of variables to their completely free use and automatic conversion of types as needed, the path was much longer.

All in the world there are lines

With this you can argue, but there is no special sense, and inprogramming - even more so. The semantics of explode PHP greatly simplified the work of the programmer: she transferred the use of several functions and constructions into one.

При этом синтаксис и семантика самого PHP в This function gives the developer the opportunity to come up with his own semantics due to this function, although other string functions will have decent work.

There is nothing easier: explode PHP simply breaks one line by the places of entry into it of another line. Typically, this is a single character:

  • comma ",";
  • dot ".";
  • slash "/";
  • tilde "~";
  • and anything you like to the taste of the developer.

But you can break a line by anything, and the second line (delimiter) can have the meaning of an entire tag, tag element, or carry in itself any value within the imagination of the programmer.

The case where the number is a string

Numbers tend to participate in mathematical operations, and lines - in the lowercase. The idea is correct and interesting, but old and useless.

Today, a variable can change type along the way fromone operator to another, and in each syntactic construction, all the variables that participate in it are of the type that determines the syntax of this construction.

So if the number falls into the line structure,it becomes a string, and if a string participates in a mathematical operation, then all its beginning before the first occurrence of a non-digit character will be interpreted as a number.

The author's example is not a picture

In this code, explode in PHP demonstrates how you can easily separate the integer part from the fractional part with any number of digits. The result of the execution of the above code is presented below.

The author's example is not a picture

It is doubtful that such a meaning was embedded in this function by the creators of the language. But there are a great many options for such an application for this function.

It should be borne in mind that the delimiter disappears, that is, after splitting the line explode PHP extracts from it all the delimiter found.

The case where the string is an array

In the given example, the string of numbers is broken by explode PHP by comma, and an array is created. The reverse PHP implode function can merge this array into a single line, for example, through a dot.

explode in php

In the first case, the string does not change, in the second case, the array also remains. In other words, using strings, you can split on one base, and connect differently.

In the first approximation, you can, for example, performsubstitution of lowercase letters for uppercase. Such a task for explode / implode will probably not be very interesting, but the important moment is that there can be any partition! How to connect is also any option.

Lines and objects

Object-oriented programming todayeverywhere, and any program consists of objects. Naturally, PHP explode description never mentioned objects, but nothing prevents you from creating the idea of ​​a direct connection between strings and objects.

In this context, an object can be represented.a string of characters, placing it in a database or transmitting it over communication channels. It is possible to organize the exchange of information between objects not through cumbersome arrays, but through parameter strings.

php explode description

The sender combines the necessary data into a single whole (string), and the recipient uses PHP to restore it, that is, it extracts the necessary sequences of characters.

If you develop this idea at the time when the object is created, then usually you have to “manually” or fill it with the necessary data from the database.

Using explode, you can automate the process.creating instances of an object, and having an abstract object, you can control its type by passing various strings of characters to initialize. This approach reduces the number of different objects and simplifies the manipulation of them.

Liked:
0
Popular Posts
Spiritual development
Food
yup