ComputersProgramming

PHP: the last element. Array in dynamics

PHP - this is perspective and modern: high-quality syntax and the ability to make semantics beyond what is permissible. The implementation of the ideas of object-oriented programming and the freedom to change the type of the variable makes the boldest fantasies a reality.

Arrays are an ancient construction, and associative - rather a tribute to time, rather than the requirement of practice. Although there are a sufficient number of tasks that involve the creation of aggregates of data not previously provided for in the content (number, values, types and indices) that are available for viewing and use in PHP foreach cycles . The last element of the array is available for any method of creation. Array - normal and associative - allow you to create lists, but in the usual PHP syntax this has limited application.

The actual value of the array

If we abstract out the indices and use the construction

$ ArData [] = new scField (); // scNumber, scString, scParagraph, ...

Where scField () is the constructor of an abstract object - an "information item" that has heirs: numbers (scNumber), strings (scString), phrases (scParagraph), ... we get in PHP: last element = array of objects showing its properties as Actual element.

In essence, it does not matter which element is considered relevant, but in this case you have to follow the pointer (in PHP - the cursor) inside the array. More often - you need to have your own element pointer. Necessity in the cursor is devoid of the idea of PHP "last element = array". Available through the end () and array_pop () functions, the last element delegates its properties to the array. Using array_pop (), in addition, automatically takes the array to the previous element, and its properties change accordingly. This makes it possible to move around the elements.

Thus, considering in the context of PHP syntax, extracting the last element of an array actually means using its properties. Sequentially, placing and extracting elements, we obtain the dynamics of properties, the dynamics of the new data structure formed within the available syntax.

The first and other elements

There are functions for working with the first element of the array and moving the internal pointer. In the usual syntax that implements classical programming practice, they are applicable. With respect to the creation of arrays with dynamically changing meanings - no.

In programming, it is always about making decisions: variables take values, condition statements change the course of the algorithm, the cycles analyze something, and eventually the result is produced.

If you transfer the center of gravity to the element itself and let it make its own decisions, the implementation of the program takes on a completely different, meaningful form. Most often this is the way to achieve the goal, especially when it comes to, for example, the use of multiple tags of the * .docx document, written in the standard of Open XML.

In PHP, getting the last element of the array is a new meaning and good possibilities.

Loading files and dynamics of array properties

When a site provides the ability to upload any files, it is convenient to use the idea of an abstract object, for example, scFile and descendants of it scImage, scDocument, scTabe, which will have the same properties but different manifestations and meaning. In the context of the PHP syntax (last element = array), using the end () function, you can use it as it defines the last element. This solution is interesting because it inverts the usual representations and allows you to navigate the data structure as it was formed.

This use of arrays gives them a completely new content. This is provided by the syntax of PHP, but such use opens up wide possibilities.

By providing methods of visualization, saving in the database, restoring in working order (for example), you will not have to think about what to do in a particular case. All downloaded files are placed in an array sequentially, and when it is processed, the same methods are always called on the same scheme, but the picture file will be displayed as is, the spreadsheet file as a table, and the document as the corresponding text. The last element accessible via the PHP syntax, the array equips with its properties and specific content.

In the latter case, the document always has characters, strings, numbers, and, most importantly, formatting. It is difficult to keep track of each element, but by providing a proper object for each element of the format, you can get the document as it is without hesitation.

Stack and recursion within the syntax

When only the last element is working, the main condition is the stack, but when this element is executed and it uses the same construction, and especially it itself, it is recursion. You can say a lot of good things about PHPOffice libraries, for example PHPWord, but you can not say that they implement a full mechanism that translates the original formatting of a document into a result.

Indeed, using PHPOffice \ PHPWord you can open any Vordian document (* .docx), but this is just an archive of a set of structured xml-files, drawings, objects, etc.

However, if you take only xml-files, although they are interrelated (in terms of styles, tables, pictures), you will not be able to create a new document based on the old one and just transfer the desired changes to it (for example, change the font, colors, formatting). There are many options for using Open XML tags, and even a product as debugged as MS Word does not always cope with the user's ideas, making mistakes.

Actually * .docx file is a zip-archive, and a clear and understandable structure. Using a small number of objects, you can formally describe it and get a complete, independent data structure at the time of reading, which you can manage semantically.

In this case, the information in the document is a formal data structure. By giving it dynamics, you can easily go to the level of meaning and abstract from the syntax.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.birmiss.com. Theme powered by WordPress.